-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
6 changed files
with
107 additions
and
1 deletion.
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
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,62 @@ | ||
import { createStore, fillState, assertState } from 'test/Helpers' | ||
import { Model, Attr, Str } from '@/index' | ||
|
||
describe('feature/repository/inserts_fresh', () => { | ||
class User extends Model { | ||
static entity = 'users' | ||
|
||
@Attr() id!: any | ||
@Str('') name!: string | ||
} | ||
|
||
it('inserts a new record to the store', async () => { | ||
const store = createStore() | ||
|
||
await store.$repo(User).fresh({ id: 1, name: 'John Doe' }) | ||
|
||
assertState(store, { | ||
users: { | ||
1: { id: 1, name: 'John Doe' } | ||
} | ||
}) | ||
}) | ||
|
||
it('inserts multiple records to the store', async () => { | ||
const store = createStore() | ||
|
||
await store.$repo(User).fresh([ | ||
{ id: 1, name: 'John Doe' }, | ||
{ id: 2, name: 'Jane Doe' } | ||
]) | ||
|
||
assertState(store, { | ||
users: { | ||
1: { id: 1, name: 'John Doe' }, | ||
2: { id: 2, name: 'Jane Doe' } | ||
} | ||
}) | ||
}) | ||
|
||
it('replaces existing records', async () => { | ||
const store = createStore() | ||
|
||
fillState(store, { | ||
users: { | ||
1: { id: 1, name: 'John Doe' }, | ||
2: { id: 2, name: 'Jane Doe' } | ||
} | ||
}) | ||
|
||
await store.$repo(User).fresh([ | ||
{ id: 3, name: 'Johnny Doe' }, | ||
{ id: 4, name: 'David Doe' } | ||
]) | ||
|
||
assertState(store, { | ||
users: { | ||
3: { id: 3, name: 'Johnny Doe' }, | ||
4: { id: 4, name: 'David Doe' } | ||
} | ||
}) | ||
}) | ||
}) |