diff --git a/packages/falso/src/tests/core/date-is-unique.spec.ts b/packages/falso/src/tests/core/date-is-unique.spec.ts new file mode 100644 index 000000000..030c30f53 --- /dev/null +++ b/packages/falso/src/tests/core/date-is-unique.spec.ts @@ -0,0 +1,32 @@ +import { dateIsUnique } from '../../lib/core/unique-validators'; +import { randPastDate } from '@ngneat/falso'; + +describe('dateIsUnique', () => { + let dates: Date[]; + let date1: Date; + let date2: Date; + let date3: Date; + + beforeEach(() => { + date1 = randPastDate(); + date2 = randPastDate(); + date3 = randPastDate(); + dates = [date1, date2]; + }); + + describe('date is unique', () => { + it('should return true', () => { + const result = dateIsUnique(date3, dates); + + expect(result).toEqual(true); + }); + }); + + describe('date is not unique', () => { + it('should return false', () => { + const result = dateIsUnique(date2, dates); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/packages/falso/src/tests/core/object-with-id-is-unique.spec.ts b/packages/falso/src/tests/core/object-with-id-is-unique.spec.ts new file mode 100644 index 000000000..3f23c4652 --- /dev/null +++ b/packages/falso/src/tests/core/object-with-id-is-unique.spec.ts @@ -0,0 +1,46 @@ +import { objectWithIdIsUnique } from '../../lib/core/unique-validators'; +import { randFullName, randNumber } from '@ngneat/falso'; + +describe('objectWithIdIsUnique', () => { + let objects: any[]; + let object1: any; + let object2: any; + let object3: any; + + beforeEach(() => { + const name = randFullName(); + const age = randNumber({ min: 10, max: 90 }); + object1 = { + id: '1', + name, + age, + }; + object2 = { + id: '2', + name, + age, + }; + object3 = { + id: '3', + name, + age, + }; + objects = [object1, object2]; + }); + + describe('object id is unique', () => { + it('should return true', () => { + const result = objectWithIdIsUnique(object3, objects); + + expect(result).toEqual(true); + }); + }); + + describe('object id is not unique', () => { + it('should return false', () => { + const result = objectWithIdIsUnique(object2, objects); + + expect(result).toEqual(false); + }); + }); +}); diff --git a/packages/falso/src/tests/core/primitive-value-is-unique.spec.ts b/packages/falso/src/tests/core/primitive-value-is-unique.spec.ts new file mode 100644 index 000000000..abfbd08d2 --- /dev/null +++ b/packages/falso/src/tests/core/primitive-value-is-unique.spec.ts @@ -0,0 +1,32 @@ +import { primitiveValueIsUnique } from '../../lib/core/unique-validators'; +import { randNumber } from '@ngneat/falso'; + +describe('primitiveValueIsUnique', () => { + let items: number[]; + let item1: number; + let item2: number; + let item3: number; + + beforeEach(() => { + item1 = randNumber(); + item2 = randNumber(); + item3 = randNumber(); + items = [item1, item2]; + }); + + describe('item is unique', () => { + it('should return true', () => { + const result = primitiveValueIsUnique(item3, items); + + expect(result).toEqual(true); + }); + }); + + describe('item is not unique', () => { + it('should return false', () => { + const result = primitiveValueIsUnique(item2, items); + + expect(result).toEqual(false); + }); + }); +});