CyCraft / CyCraft/magnetar

docs: write explanation on how to inherit modifyPayloadOn & modifyReadResponseOn

Open
#30 0 comments 0 reactions 0 assignees View on GitHub
documentation
Dominant language
TypeScript
Stars
46
Forks
6
PR merge metrics
No merged PRs in 30d

Description

basically I need to write explanation for what's happening here:
```ts
test('insert: can mutate payload (config in module - action from doc)', async (t) => {
function addSeen(payload: any) {
if (!('seen' in payload)) return { ...payload, seen: true }
}
// get resolves once all stores have given a response with data
const { magnetar } = createMagnetarInstance()
const pokedexModule = magnetar.collection('pokedex', {
modifyPayloadOn: { write: addSeen },
})
try {
const resultWithoutSeen = await magnetar.collection('pokedex').doc('10').insert(pokedex(10))
const resultWithSeen = await pokedexModule.doc('7').insert(pokedex(7))
// the remote result not from pokedexModule SHOULD NOT HAVE the applied defaults
t.deepEqual(resultWithoutSeen.data, { ...pokedex(10) })
t.falsy('seen' in resultWithoutSeen)
// the remote result SHOULD HAVE the applied defaults
t.deepEqual(resultWithSeen.data, { ...pokedex(7), seen: true })
} catch (error) {
t.fail(error)
}
// the local store result not from pokedexModule SHOULD NOT HAVE the applied defaults
t.deepEqual(pokedexModule.data.get('7'), { ...pokedex(7), seen: true })
// the local store SHOULD HAVE the applied defaults
t.deepEqual(pokedexModule.data.get('10'), { ...pokedex(10) })
})
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.