-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(createMany): add createMany api
- Loading branch information
Rory Jennings
committed
Sep 2, 2022
1 parent
951b2c8
commit 8192aa5
Showing
5 changed files
with
108 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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import faker from '@faker-js/faker'; | ||
import { factory, nullable, primaryKey } from '../../src'; | ||
|
||
const db = factory({ | ||
user: { | ||
id: primaryKey(String), | ||
firstName: String, | ||
lastName: nullable(faker.name.lastName), | ||
age: nullable<number>(() => null), | ||
address: { | ||
billing: { | ||
country: String, | ||
}, | ||
}, | ||
}, | ||
company: { | ||
name: primaryKey(String), | ||
}, | ||
}) | ||
|
||
// Most assertions are covered by create.test-d.ts, as | ||
// createMany calls it internally | ||
|
||
// @ts-expect-error Expected at least 1 arguments, but got 0. | ||
db.user.createMany() | ||
|
||
db.user.createMany( | ||
{}, | ||
{ | ||
// @ts-expect-error Property "secondName" does not exist on "user". | ||
secondName: 'any' | ||
} | ||
) |
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 faker from '@faker-js/faker' | ||
import { factory, identity, primaryKey } from '../../src' | ||
|
||
test('creates a single new entity', () => { | ||
const userId = faker.datatype.uuid() | ||
const db = factory({ | ||
user: { | ||
id: primaryKey(identity(userId)), | ||
}, | ||
}) | ||
|
||
const users = db.user.createMany({}) | ||
expect(users.length).toEqual(1) | ||
expect(users[0].id).toEqual(userId) | ||
}) | ||
|
||
test('creates multiple new entities', () => { | ||
const db = factory({ | ||
user: { | ||
id: primaryKey(faker.datatype.uuid), | ||
}, | ||
}) | ||
|
||
const users = db.user.createMany({}, {}, {}) | ||
expect(users.length).toEqual(3) | ||
}) | ||
|
||
test('creates entities using the set values', () => { | ||
const db = factory({ | ||
user: { | ||
id: primaryKey(faker.datatype.uuid), | ||
}, | ||
}) | ||
|
||
const users = db.user.createMany({ | ||
id: 'abc-123', | ||
}, { | ||
id: 'def-456', | ||
}, { | ||
id: 'ghi-789', | ||
}) | ||
expect(users.length).toEqual(3) | ||
expect(users[0].id).toEqual('abc-123') | ||
expect(users[1].id).toEqual('def-456') | ||
expect(users[2].id).toEqual('ghi-789') | ||
}) |