Skip to content

Commit

Permalink
Add unit tests for UPSERT_RESOURCE and UPDATE_RESOURCE
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jun 11, 2021
1 parent 7b0c3d8 commit 9c6c6bb
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/web-app-files/tests/store/mutations.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import mutations from '../../src/store/mutations'
import { cloneDeep } from 'lodash-es'

const stateFixture = {
files: [
{
id: 1,
name: 'test1'
},
{
id: 2,
name: 'test2'
},
{
id: 5,
name: 'test5'
}
]
}
let stateMock = {}
const resetState = () => {
stateMock = cloneDeep(stateFixture)
}

describe('vuex store mutations', () => {
describe('update resources by id', () => {
beforeEach(resetState)
it.each([
[mutations.UPSERT_RESOURCE.name, mutations.UPSERT_RESOURCE],
[mutations.UPDATE_RESOURCE.name, mutations.UPDATE_RESOURCE]
])('succeeds using mutation %s', (name, m) => {
expect(stateMock.files).toEqual(stateFixture.files)
expect(stateMock.files[1].name).toBe('test2')
m(stateMock, {
id: 2,
name: 'test2-updated'
})
expect(stateMock.files[1].name).toBe('test2-updated')
expect(stateMock.files.length).toBe(stateFixture.files.length)
})
})
describe('insert resources', () => {
beforeEach(resetState)
it('succeeds using mutation UPSERT_RESOURCE', () => {
expect(stateMock.files).toEqual(stateFixture.files)
mutations.UPSERT_RESOURCE(stateMock, {
id: 3,
name: 'test3-inserted'
})
expect(stateMock.files).toEqual([...stateFixture.files, { id: 3, name: 'test3-inserted' }])
})
it('is ignored using mutation UPDATE_RESOURCE', () => {
expect(stateMock.files).toEqual(stateFixture.files)
mutations.UPDATE_RESOURCE(stateMock, {
id: 3,
name: 'test3-inserted'
})
expect(stateMock.files).toEqual(stateFixture.files)
})
})
})

0 comments on commit 9c6c6bb

Please sign in to comment.