Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jun 4, 2024
1 parent b5a2a9c commit 1c8fe15
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/core/test/internal/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { merge } from 'merge-anything'
import { assert, test } from 'vitest'
import { createMagnetarInstance } from '../helpers/createMagnetarInstance.js'

test('write: insert (document)', async () => {
test('write: insert (document) → set ID via doc instance', async () => {
const { pokedexModule, magnetar } = createMagnetarInstance()
const payload = pokedex(7)
assert.deepEqual(pokedexModule.data.get('7'), undefined)
Expand All @@ -17,6 +17,20 @@ test('write: insert (document)', async () => {
assert.deepEqual(magnetar.collection('pokedex').doc('7').data, payload)
})

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

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

0 comments on commit 1c8fe15

Please sign in to comment.