From b7578a5db374487cfb1bbc1185ad08156dc66641 Mon Sep 17 00:00:00 2001 From: Max Polsky Date: Sun, 10 Dec 2023 13:47:39 +0200 Subject: [PATCH] refactor: review changes --- .../velo-external-db/test/e2e/app_data.e2e.spec.ts | 14 +++++++------- .../test/e2e/app_data_hooks.e2e.spec.ts | 12 +++++++----- .../src/converters/data_utils.ts | 2 +- libs/velo-external-db-core/src/service/data.ts | 2 +- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts b/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts index 7e91a90a9..0c883210f 100644 --- a/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts +++ b/apps/velo-external-db/test/e2e/app_data.e2e.spec.ts @@ -3,7 +3,7 @@ import each from 'jest-each' import * as Chance from 'chance' import { Uninitialized, gen as genCommon, testIfSupportedOperationsIncludes } from '@wix-velo/test-commons' import { InputField, SchemaOperations, Item } from '@wix-velo/velo-external-db-types' -import { dataSpi, dataConvertUtils } from '@wix-velo/velo-external-db-core' +import { dataSpi } from '@wix-velo/velo-external-db-core' import { authAdmin, authOwner, authVisitor } from '@wix-velo/external-db-testkit' import * as gen from '../gen' import * as schema from '../drivers/schema_api_rest_test_support' @@ -88,9 +88,9 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () expect(response.data.results).toStrictEqual([ - dataConvertUtils.asWixDataItem(ctx.items[0]), + { item: ctx.items[0] }, { error: { errorCode: 409, errorMessage: expect.toInclude('Item already exists'), data: expect.any(Object) } }, - ...(ctx.items.slice(2, ctx.items.length).map(dataConvertUtils.asWixDataItem)), + ...(ctx.items.slice(2, ctx.items.length).map( item => ({ item }) )), ]) await expect(data.queryCollectionAsArray(ctx.collectionName, [], undefined, authOwner)).resolves.toEqual({ @@ -145,7 +145,7 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () collectionId: ctx.collectionName, itemIds: ctx.items.map(i => i._id) }, authAdmin) - expect(response.data.results).toEqual(expect.toIncludeSameMembers(ctx.items.map(dataConvertUtils.asWixDataItem))) + expect(response.data.results).toEqual(expect.toIncludeSameMembers(ctx.items.map( item => ({ item }) ) )) await expect(data.queryCollectionAsArray(ctx.collectionName, [], undefined, authOwner)).resolves.toEqual({ items: [], pagingMetadata: data.pagingMetadata(0, 0) @@ -161,7 +161,7 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () }, authAdmin) expect(response.data.results).toStrictEqual([ - dataConvertUtils.asWixDataItem(ctx.items[0]), + { item: ctx.items[0] }, ...ctx.items.slice(1, ctx.items.length).map(_i => ({ error: { errorCode: 404, @@ -227,7 +227,7 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () await data.givenItems(ctx.items, ctx.collectionName, authAdmin) const response = await axiosInstance.post('/items/update', data.updateRequest(ctx.collectionName, ctx.modifiedItems), authAdmin) - expect(response.data.results).toEqual(ctx.modifiedItems.map(dataConvertUtils.asWixDataItem)) + expect(response.data.results).toEqual(ctx.modifiedItems.map( item => ({ item }) )) await expect(data.queryCollectionAsArray(ctx.collectionName, [], undefined, authOwner)).resolves.toEqual({ items: expect.toIncludeSameMembers(ctx.modifiedItems), @@ -241,7 +241,7 @@ describe(`Velo External DB Data REST API: ${currentDbImplementationName()}`, () const response = await axiosInstance.post('/items/update', data.updateRequest(ctx.collectionName, ctx.modifiedItems), authAdmin) expect(response.data.results).toEqual([ - ...(ctx.modifiedItems.slice(0, ctx.items.length - 1).map(dataConvertUtils.asWixDataItem)), + ...(ctx.modifiedItems.slice(0, ctx.items.length - 1).map( item => ({ item }))), { error: { errorCode: 404, diff --git a/apps/velo-external-db/test/e2e/app_data_hooks.e2e.spec.ts b/apps/velo-external-db/test/e2e/app_data_hooks.e2e.spec.ts index 2355f43dd..8b3cd87f8 100644 --- a/apps/velo-external-db/test/e2e/app_data_hooks.e2e.spec.ts +++ b/apps/velo-external-db/test/e2e/app_data_hooks.e2e.spec.ts @@ -499,11 +499,13 @@ describe(`Velo External DB Data Hooks: ${currentDbImplementationName()}`, () => await expect(response.data).toEqual({ results: [{ - ...ctx.item, - [ctx.afterAllColumn.name]: true, - [ctx.afterWriteColumn.name]: true, - [ctx.afterHookColumn.name]: true, - }].map(dataConvertUtils.asWixDataItem) + item: { + ...ctx.item, + [ctx.afterAllColumn.name]: true, + [ctx.afterWriteColumn.name]: true, + [ctx.afterHookColumn.name]: true, + } + }] }) }) }) diff --git a/libs/velo-external-db-core/src/converters/data_utils.ts b/libs/velo-external-db-core/src/converters/data_utils.ts index 59ecd8406..0281f38c0 100644 --- a/libs/velo-external-db-core/src/converters/data_utils.ts +++ b/libs/velo-external-db-core/src/converters/data_utils.ts @@ -8,7 +8,7 @@ export const asWixData = (item: Item) => { } export const asWixDataItem = (item: Item) => { - return { item: generateIdsIfNeeded(packDates(item)) } + return { item: asWixData(item) } } export const generateIdsIfNeeded = (item: Item): ItemWithId => { diff --git a/libs/velo-external-db-core/src/service/data.ts b/libs/velo-external-db-core/src/service/data.ts index 276f8cb61..a7e15e40e 100644 --- a/libs/velo-external-db-core/src/service/data.ts +++ b/libs/velo-external-db-core/src/service/data.ts @@ -57,7 +57,7 @@ export default class DataService { async bulkUpdate(collectionName: string, _items: Item[]) { const items = await Promise.all((_items.map( item => this.storage.update(collectionName, [item]) // maybe we should throw from data provider if affectedRows equals to 0 - .then(affectedRows => affectedRows === 1 ?asWixDataItem(item) : Promise.reject(new domainErrors.ItemDoesNotExists(`Item doesn't exists: ${item._id}`, collectionName, item._id))) + .then(affectedRows => affectedRows === 1 ? asWixDataItem(item) : Promise.reject(new domainErrors.ItemDoesNotExists(`Item doesn't exists: ${item._id}`, collectionName, item._id))) .catch(e => domainToSpiErrorObjectTranslator(e))) ))