-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
89 changed files
with
3,369 additions
and
4,888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
**/lib | ||
**/*.tests.js | ||
**/*.test.js | ||
**/*.tests.ts | ||
**/*.test.ts | ||
**/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 22 additions & 19 deletions
41
packages/core-enrollments/src/module/buildFindSelector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import { EnrollmentStatus } from "@unchainedshop/core-enrollments"; | ||
import { buildFindSelector } from "./configureEnrollmentsModule.js"; | ||
import { EnrollmentStatus } from '@unchainedshop/core-enrollments'; | ||
import { buildFindSelector } from './configureEnrollmentsModule.js'; | ||
|
||
describe('buildFindSelector', () => { | ||
it('Should correct filter when passed status, userId and queryString', () => { | ||
expect(buildFindSelector({queryString: "Hello World", status: [EnrollmentStatus.ACTIVE], userId: 'admin-id'})).toEqual({ | ||
expect( | ||
buildFindSelector({ | ||
queryString: 'Hello World', | ||
status: [EnrollmentStatus.ACTIVE], | ||
userId: 'admin-id', | ||
}), | ||
).toEqual({ | ||
deleted: null, | ||
status: { '$in': [ 'ACTIVE' ] }, | ||
status: { $in: ['ACTIVE'] }, | ||
userId: 'admin-id', | ||
'$text': { '$search': 'Hello World' } | ||
}) | ||
$text: { $search: 'Hello World' }, | ||
}); | ||
}); | ||
it('Should correct filter when passed userId and queryString', () => { | ||
|
||
expect(buildFindSelector({queryString: "Hello World", userId: 'admin-id'})).toEqual({ | ||
expect(buildFindSelector({ queryString: 'Hello World', userId: 'admin-id' })).toEqual({ | ||
deleted: null, | ||
userId: 'admin-id', | ||
'$text': { '$search': 'Hello World' } | ||
}) | ||
$text: { $search: 'Hello World' }, | ||
}); | ||
}); | ||
|
||
it('Should correct filter when passed queryString', () => { | ||
|
||
expect(buildFindSelector({queryString: "Hello World"})).toEqual({ | ||
deleted: null, | ||
'$text': { '$search': 'Hello World' } | ||
}) | ||
expect(buildFindSelector({ queryString: 'Hello World' })).toEqual({ | ||
deleted: null, | ||
$text: { $search: 'Hello World' }, | ||
}); | ||
}); | ||
|
||
it('Should correct filter when passed no argument', () => { | ||
|
||
expect(buildFindSelector({})).toEqual({ | ||
deleted: null, | ||
}) | ||
deleted: null, | ||
}); | ||
}); | ||
}) | ||
}); |
38 changes: 23 additions & 15 deletions
38
packages/core-events/src/module/buildFindSelector.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { buildFindSelector } from "./configureEventsModule.js"; | ||
import { buildFindSelector } from './configureEventsModule.js'; | ||
|
||
describe('buildFindSelector', () => { | ||
it('Return correct filter object when passed create, queryString, types', () => { | ||
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z"), queryString: "Hello world", types: ['PRODUCT_CREATED']})).toEqual({ | ||
type: { '$in': [ 'PRODUCT_CREATED' ] }, | ||
'$text': { '$search': 'Hello world' }, | ||
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )} | ||
}) | ||
expect( | ||
buildFindSelector({ | ||
created: new Date('2022-12-03T18:23:38.278Z'), | ||
queryString: 'Hello world', | ||
types: ['PRODUCT_CREATED'], | ||
}), | ||
).toEqual({ | ||
type: { $in: ['PRODUCT_CREATED'] }, | ||
$text: { $search: 'Hello world' }, | ||
created: { $gte: new Date('2022-12-03T18:23:38.278Z') }, | ||
}); | ||
}); | ||
|
||
it('Return correct filter object when passed create, queryString', () => { | ||
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z"), queryString: "Hello world"})).toEqual({ | ||
'$text': { '$search': 'Hello world' }, | ||
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )} | ||
}) | ||
expect( | ||
buildFindSelector({ created: new Date('2022-12-03T18:23:38.278Z'), queryString: 'Hello world' }), | ||
).toEqual({ | ||
$text: { $search: 'Hello world' }, | ||
created: { $gte: new Date('2022-12-03T18:23:38.278Z') }, | ||
}); | ||
}); | ||
|
||
it('Return correct filter object when passed create', () => { | ||
expect(buildFindSelector({created: new Date("2022-12-03T18:23:38.278Z")})).toEqual({ | ||
created: { '$gte': new Date( "2022-12-03T18:23:38.278Z" )} | ||
}) | ||
expect(buildFindSelector({ created: new Date('2022-12-03T18:23:38.278Z') })).toEqual({ | ||
created: { $gte: new Date('2022-12-03T18:23:38.278Z') }, | ||
}); | ||
}); | ||
|
||
it('Return correct filter object when passed no argument', () => { | ||
expect(buildFindSelector({})).toEqual({}) | ||
expect(buildFindSelector({})).toEqual({}); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import { intersectSet } from "./intersectSet.js"; | ||
import { intersectSet } from './intersectSet.js'; | ||
|
||
describe('intersectSet', () => { | ||
it('should return an empty set if the two input sets are empty', () => { | ||
const productIdSet: Set<string> = new Set(); | ||
const filterProductIdSet: Set<string> = new Set(); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set()); | ||
}); | ||
it('should return an empty set if the two input sets do not have any common elements', () => { | ||
const productIdSet = new Set(['1', '2', '3']); | ||
const filterProductIdSet = new Set(['4', '5', '6']); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set()); | ||
}); | ||
it('should return a set containing only the common elements of the two input sets', () => { | ||
const productIdSet = new Set(['1', '2', '3', '4']); | ||
const filterProductIdSet = new Set(['2', '3', '5', '6']); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set(['2', '3'])); | ||
}); | ||
it('should not modify the original input sets', () => { | ||
const productIdSet = new Set(['1', '2', '3']); | ||
const filterProductIdSet = new Set(['2', '3', '4', '5']); | ||
intersectSet(productIdSet, filterProductIdSet); | ||
expect(productIdSet).toEqual(new Set(['1', '2', '3'])); | ||
expect(filterProductIdSet).toEqual(new Set(['2', '3', '4', '5'])); | ||
}); | ||
}); | ||
describe('intersectSet', () => { | ||
it('should return an empty set if the two input sets are empty', () => { | ||
const productIdSet: Set<string> = new Set(); | ||
const filterProductIdSet: Set<string> = new Set(); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set()); | ||
}); | ||
|
||
it('should return an empty set if the two input sets do not have any common elements', () => { | ||
const productIdSet = new Set(['1', '2', '3']); | ||
const filterProductIdSet = new Set(['4', '5', '6']); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set()); | ||
}); | ||
|
||
it('should return a set containing only the common elements of the two input sets', () => { | ||
const productIdSet = new Set(['1', '2', '3', '4']); | ||
const filterProductIdSet = new Set(['2', '3', '5', '6']); | ||
const result = intersectSet(productIdSet, filterProductIdSet); | ||
expect(result).toEqual(new Set(['2', '3'])); | ||
}); | ||
|
||
it('should not modify the original input sets', () => { | ||
const productIdSet = new Set(['1', '2', '3']); | ||
const filterProductIdSet = new Set(['2', '3', '4', '5']); | ||
intersectSet(productIdSet, filterProductIdSet); | ||
expect(productIdSet).toEqual(new Set(['1', '2', '3'])); | ||
expect(filterProductIdSet).toEqual(new Set(['2', '3', '4', '5'])); | ||
}); | ||
}); |
Oops, something went wrong.