Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jun 4, 2024
1 parent 1c8fe15 commit ebfa20e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/core/test/internal/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ test('write: insert (document) → set ID via payload', async () => {
assert.deepEqual(magnetar.collection('pokedex').doc('007').data, payload as any)
})

test('write: insert (document) → set ID via hook', async () => {
const { pokedexModule, magnetar } = createMagnetarInstance()
const payload = pokedex(7)
assert.deepEqual(pokedexModule.data.get('7'), undefined)
assert.deepEqual(pokedexModule.data.get('007'), undefined)
await pokedexModule.insert(payload, {
modifyPayloadOn: {
insert: (_payload) => ({..._payload, id: '007'} as any),
},
}).catch((e: any) => assert.fail(e.message)) // prettier-ignore
// check data of references executed on
assert.deepEqual(pokedexModule.data.get('007'), { ...payload, id: '007' } as any)
// check data of new references
assert.deepEqual(pokedexModule.doc('007').data, { ...payload, id: '007' } as any)
assert.deepEqual(magnetar.doc('pokedex/007').data, { ...payload, id: '007' } as any)
assert.deepEqual(magnetar.collection('pokedex').doc('007').data, { ...payload, id: '007' } as any)
})

test('write: insert (collection) → random ID', async () => {
const { pokedexModule, magnetar } = createMagnetarInstance()
const payload = pokedex(7)
Expand Down

0 comments on commit ebfa20e

Please sign in to comment.