-
-
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.
Co-authored-by: Cue <1493221+cuebit@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
336 additions
and
17 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
34 changes: 34 additions & 0 deletions
34
test/feature/repository/deletes_destroy_composite_key.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,34 @@ | ||
import { createStore, fillState } from 'test/Helpers' | ||
import { Model, Attr, Str } from '@/index' | ||
|
||
describe('feature/repository/deletes_destroy_composite_key', () => { | ||
class User extends Model { | ||
static entity = 'users' | ||
|
||
static primaryKey = ['idA', 'idB'] | ||
|
||
@Attr() idA!: any | ||
@Attr() idB!: any | ||
@Str('') name!: string | ||
} | ||
|
||
it('throws if the model has composite key', async () => { | ||
expect.assertions(1) | ||
|
||
const store = createStore() | ||
|
||
fillState(store, { | ||
users: { | ||
1: { id: 1, name: 'John Doe' }, | ||
2: { id: 2, name: 'Jane Doe' }, | ||
3: { id: 3, name: 'Johnny Doe' } | ||
} | ||
}) | ||
|
||
try { | ||
await store.$repo(User).destroy(2) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
test/feature/repository/inserts_fresh_composite_key.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,42 @@ | ||
import { createStore, assertState } from 'test/Helpers' | ||
import { Model, Attr, Str } from '@/index' | ||
|
||
describe('feature/repository/inserts_fresh_composite_key', () => { | ||
class User extends Model { | ||
static entity = 'users' | ||
|
||
static primaryKey = ['idA', 'idB'] | ||
|
||
@Attr() idA!: any | ||
@Attr() idB!: any | ||
@Str('') name!: string | ||
} | ||
|
||
it('inserts records with the composite key', async () => { | ||
const store = createStore() | ||
|
||
await store.$repo(User).fresh([ | ||
{ idA: 1, idB: 2, name: 'John Doe' }, | ||
{ idA: 2, idB: 1, name: 'Jane Doe' } | ||
]) | ||
|
||
assertState(store, { | ||
users: { | ||
'[1,2]': { idA: 1, idB: 2, name: 'John Doe' }, | ||
'[2,1]': { idA: 2, idB: 1, name: 'Jane Doe' } | ||
} | ||
}) | ||
}) | ||
|
||
it('throws if the one of the composite key is missing', async () => { | ||
expect.assertions(1) | ||
|
||
const store = createStore() | ||
|
||
try { | ||
await store.$repo(User).insert({ idA: 1, name: 'John Doe' }) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
test/feature/repository/inserts_insert_composite_key.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,42 @@ | ||
import { createStore, assertState } from 'test/Helpers' | ||
import { Model, Attr, Str } from '@/index' | ||
|
||
describe('feature/repository/inserts_insert_composite_key', () => { | ||
class User extends Model { | ||
static entity = 'users' | ||
|
||
static primaryKey = ['idA', 'idB'] | ||
|
||
@Attr() idA!: any | ||
@Attr() idB!: any | ||
@Str('') name!: string | ||
} | ||
|
||
it('inserts records with the composite key', async () => { | ||
const store = createStore() | ||
|
||
await store.$repo(User).insert([ | ||
{ idA: 1, idB: 2, name: 'John Doe' }, | ||
{ idA: 2, idB: 1, name: 'Jane Doe' } | ||
]) | ||
|
||
assertState(store, { | ||
users: { | ||
'[1,2]': { idA: 1, idB: 2, name: 'John Doe' }, | ||
'[2,1]': { idA: 2, idB: 1, name: 'Jane Doe' } | ||
} | ||
}) | ||
}) | ||
|
||
it('throws if the one of the composite key is missing', async () => { | ||
expect.assertions(1) | ||
|
||
const store = createStore() | ||
|
||
try { | ||
await store.$repo(User).insert({ idA: 1, name: 'John Doe' }) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
54 changes: 54 additions & 0 deletions
54
test/feature/repository/updates_update_composite_key.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,54 @@ | ||
import { createStore, fillState, assertState } from 'test/Helpers' | ||
import { Model, Attr, Str, Num } from '@/index' | ||
|
||
describe('feature/repository/updates_update_composite_key', () => { | ||
class User extends Model { | ||
static entity = 'users' | ||
|
||
static primaryKey = ['idA', 'idB'] | ||
|
||
@Attr() idA!: any | ||
@Attr() idB!: any | ||
@Str('') name!: string | ||
@Num(0) age!: number | ||
} | ||
|
||
it('update records with composite key', async () => { | ||
const store = createStore() | ||
|
||
fillState(store, { | ||
users: { | ||
'[1,2]': { idA: 1, idB: 2, name: 'John Doe', age: 40 }, | ||
'[2,1]': { idA: 2, idB: 1, name: 'Jane Doe', age: 30 } | ||
} | ||
}) | ||
|
||
await store.$repo(User).update({ idA: 2, idB: 1, age: 50 }) | ||
|
||
assertState(store, { | ||
users: { | ||
'[1,2]': { idA: 1, idB: 2, name: 'John Doe', age: 40 }, | ||
'[2,1]': { idA: 2, idB: 1, name: 'Jane Doe', age: 50 } | ||
} | ||
}) | ||
}) | ||
|
||
it('throws if the one of the composite key is missing', async () => { | ||
expect.assertions(1) | ||
|
||
const store = createStore() | ||
|
||
fillState(store, { | ||
users: { | ||
'[1,2]': { idA: 1, idB: 2, name: 'John Doe', age: 40 }, | ||
'[2,1]': { idA: 2, idB: 1, name: 'Jane Doe', age: 30 } | ||
} | ||
}) | ||
|
||
try { | ||
await store.$repo(User).update({ idA: 2, age: 50 }) | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(Error) | ||
} | ||
}) | ||
}) |
Oops, something went wrong.