Skip to content

Commit bf6c824

Browse files
committed
delete store function integration tests
1 parent d1bcc7e commit bf6c824

File tree

9 files changed

+78
-11
lines changed

9 files changed

+78
-11
lines changed

src/integrationTests/common.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ export const test = (
2323
): Test => async (stores: Stores) => {
2424
console.log(`Running test: ${name}`)
2525
const _assert = (actual: any, expected: any, message?: string): any => {
26-
try {
27-
assert.deepStrictEqual(actual, expected, message)
28-
}
29-
catch (error) {
30-
console.log('Test failed: ', error)
31-
throw error
32-
}
26+
assert.deepStrictEqual(actual, expected, message)
3327
}
3428
const timedFnResult = await timedFn(() => fn(stores, _assert))
3529
console.log('Done. Dt (ms):', formatPerformanceDtToMs(timedFnResult.dt))

src/integrationTests/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { ORM, provisionOrm } from './orm'
2+
import { deleteTests } from './tests/delete'
23
import { getTests } from './tests/get'
34
import { updateTests } from './tests/update'
45

56
const init = async () => {
67
const stores = await provisionOrm()
78
await getTests(stores)
89
await updateTests(stores)
10+
await deleteTests(stores)
911
await ORM.db.client.end()
1012
}
1113

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { DataFilterLogic, Operator } from '@samhuk/data-filter/dist/types'
2+
import { test } from '../../common'
3+
4+
export const basicTest = test('basic', async (stores, assert) => {
5+
const result = await stores.userAddress.delete({
6+
query: {
7+
filter: {
8+
logic: DataFilterLogic.AND,
9+
nodes: [
10+
{ field: 'city', op: Operator.EQUALS, val: 'London' },
11+
{ field: 'dateDeleted', op: Operator.EQUALS, val: null },
12+
],
13+
},
14+
},
15+
})
16+
17+
assert(result, 1)
18+
19+
const userAddressRecord = await stores.userAddress.get({
20+
filter: {
21+
logic: DataFilterLogic.AND,
22+
nodes: [
23+
{ field: 'city', op: Operator.EQUALS, val: 'London' },
24+
{ field: 'dateDeleted', op: Operator.EQUALS, val: null },
25+
],
26+
},
27+
})
28+
29+
assert(userAddressRecord, null)
30+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { DataFilterLogic, Operator } from '@samhuk/data-filter/dist/types'
2+
import { test } from '../../common'
3+
4+
export const fullQueryTest = test('full query', async (stores, assert) => {
5+
const result = await stores.userAddress.delete({
6+
query: {
7+
filter: {
8+
logic: DataFilterLogic.AND,
9+
nodes: [
10+
{ field: 'city', op: Operator.EQUALS, val: 'London' },
11+
{ field: 'dateDeleted', op: Operator.EQUALS, val: null },
12+
],
13+
},
14+
page: 1,
15+
pageSize: 1,
16+
},
17+
})
18+
19+
assert(result, 1)
20+
21+
const userRecord = await stores.userAddress.get({
22+
filter: {
23+
logic: DataFilterLogic.AND,
24+
nodes: [
25+
{ field: 'city', op: Operator.EQUALS, val: 'London' },
26+
{ field: 'dateDeleted', op: Operator.EQUALS, val: null },
27+
],
28+
},
29+
})
30+
31+
assert(userRecord, null)
32+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { testGroup } from '../../common'
2+
import { basicTest } from './basic'
3+
import { fullQueryTest } from './fullQuery'
4+
5+
export const deleteTests = testGroup(
6+
'delete',
7+
basicTest,
8+
fullQueryTest,
9+
)

src/integrationTests/tests/get/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Operator } from '@samhuk/data-filter/dist/types'
22
import { test } from '../../common'
33

4-
export const basicTest = test('basic get', async (stores, assert) => {
4+
export const basicTest = test('basic', async (stores, assert) => {
55
const result = await stores.user.get({
66
fields: ['name', 'email', 'dateCreated'],
77
filter: {

src/integrationTests/tests/update/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DataFilterLogic, Operator } from '@samhuk/data-filter/dist/types'
22
import { test } from '../../common'
33

4-
export const basicTest = test('basic get', async (stores, assert) => {
4+
export const basicTest = test('basic', async (stores, assert) => {
55
const result = await stores.user.update({
66
record: {
77
email: 'user1NewEmail@email.com',

src/integrationTests/tests/update/fullQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DataFilterLogic, Operator } from '@samhuk/data-filter/dist/types'
22
import { test } from '../../common'
33

4-
export const fullQueryTest = test('basic get', async (stores, assert) => {
4+
export const fullQueryTest = test('full query', async (stores, assert) => {
55
const result = await stores.user.update({
66
record: {
77
email: 'user1NewEmail@email.com',

src/integrationTests/tests/update/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { basicTest } from './basic'
33
import { fullQueryTest } from './fullQuery'
44

55
export const updateTests = testGroup(
6-
'get',
6+
'update',
77
basicTest,
88
fullQueryTest,
99
)

0 commit comments

Comments
 (0)