Skip to content

Commit

Permalink
refactor: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MXPOL committed Dec 10, 2023
1 parent 3620ad9 commit b7578a5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
14 changes: 7 additions & 7 deletions apps/velo-external-db/test/e2e/app_data.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions apps/velo-external-db/test/e2e/app_data_hooks.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}]
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion libs/velo-external-db-core/src/converters/data_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion libs/velo-external-db-core/src/service/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
))

Expand Down

0 comments on commit b7578a5

Please sign in to comment.