Skip to content

Commit

Permalink
fix: add test for FieldValue.increment to plugin-firestore-admin (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliu1003 authored Jun 25, 2024
1 parent 25b63ad commit c0910d1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/plugin-firestore-admin/test/external/fieldValue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { pokedex } from '@magnetarjs/test-utils'
import { FieldValue } from 'firebase-admin/firestore'
import { assert, expect, test } from 'vitest'
import { createMagnetarInstance } from '../helpers/createMagnetarInstance.js'
import { firestoreDeepEqual } from '../helpers/firestoreDeepEqual.js'

{
const testName = 'fieldValue increment'
test(testName, async () => {
const { pokedexModule } = await createMagnetarInstance(testName, {
insertDocs: { 'pokedex/1': pokedex(1) },
})
await firestoreDeepEqual(testName, 'pokedex/1', pokedex(1))
assert.deepEqual(pokedexModule.doc('1').data, pokedex(1))

const payload = { base: { HP: FieldValue.increment(1) as any } }
try {
await pokedexModule.doc('1').merge(payload)
} catch (error) {
assert.fail(JSON.stringify(error))
}

const _pokedex = pokedexModule.doc('1').data
const pokedexHp = _pokedex?.base.HP as any

expect(pokedexHp.constructor.name).toBe('NumericIncrementTransform')
expect(pokedexHp.operand).toBe(1)
})
}

0 comments on commit c0910d1

Please sign in to comment.