-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: π₯ Add tests for unique validators
(Still need to do tests for objectIsUnique) β Closes: #220
- Loading branch information
Ryan Smee
committed
May 6, 2022
1 parent
6f7dcc6
commit 2d0aecc
Showing
3 changed files
with
110 additions
and
0 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 |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
packages/falso/src/tests/core/object-with-id-is-unique.spec.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 |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
packages/falso/src/tests/core/primitive-value-is-unique.spec.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 |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |