Skip to content

Commit

Permalink
feat: πŸ”₯ Add tests for unique validators
Browse files Browse the repository at this point in the history
(Still need to do tests for objectIsUnique)

βœ… Closes: #220
  • Loading branch information
Ryan Smee committed May 6, 2022
1 parent 6f7dcc6 commit 2d0aecc
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/falso/src/tests/core/date-is-unique.spec.ts
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 packages/falso/src/tests/core/object-with-id-is-unique.spec.ts
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 packages/falso/src/tests/core/primitive-value-is-unique.spec.ts
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);
});
});
});

0 comments on commit 2d0aecc

Please sign in to comment.