Skip to content

Commit

Permalink
test edit conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
geohacker committed Jul 8, 2019
1 parent ab288d2 commit 39ca118
Show file tree
Hide file tree
Showing 3 changed files with 96,674 additions and 0 deletions.
110 changes: 110 additions & 0 deletions __tests__/actions/__snapshots__/edit.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,113 @@ Array [
},
]
`;

exports[`test async edit actions should raise VersionMismatchError 1`] = `
Array [
Object {
"edit": Object {
"comment": "Test",
"errors": Array [],
"id": "node/1",
"newFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/1",
"properties": Object {
"building": "yes",
"icon": "maki_marker",
"id": "node/1",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"oldFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/1",
"properties": Object {
"building": "house",
"icon": "maki_marker",
"id": "node/1",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"status": "pending",
"timestamp": 1562325975841,
"type": "modify",
},
"type": "EDIT_UPLOAD_STARTED",
},
Object {
"level": "error",
"message": "Upload failed",
"type": "SET_NOTIFICATION",
},
Object {
"edit": Object {
"comment": "Test",
"errors": Array [],
"id": "node/1",
"newFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/1",
"properties": Object {
"building": "yes",
"icon": "maki_marker",
"id": "node/1",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"oldFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/1",
"properties": Object {
"building": "house",
"icon": "maki_marker",
"id": "node/1",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"status": "pending",
"timestamp": 1562325975841,
"type": "modify",
},
"error": Object {
"code": "VersionMismatchError",
"extra": "Version mismatch: Provided 1, server had: 2 of Node 1",
"message": "This feature has been updated since you edited it",
"retryable": false,
},
"type": "EDIT_UPLOAD_FAILED",
},
]
`;
55 changes: 55 additions & 0 deletions __tests__/actions/edit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getFeature } from '../test-utils'
import fs from 'fs'
import path from 'path'
import state from '../fixtures/state.json'
import stateConflict from '../fixtures/state-conflict.json'

const middlewares = [thunk]
const mockStore = configureStore(middlewares)
Expand Down Expand Up @@ -171,4 +172,58 @@ describe('test async edit actions', () => {
expect(actions).toMatchSnapshot()
})
})

it('should raise VersionMismatchError', () => {
const store = mockStore(stateConflict)
const edit = {
oldFeature: {
'type': 'Feature',
'id': 'node/1',
'geometry': {
'type': 'Point',
'coordinates': [
-77.02937206507221,
38.89497324828185
]
},
'properties': {
'id': 'node/1',
'version': 1,
'name': 'Test',
'building': 'house',
'icon': 'maki_marker'
}
},
newFeature: {
'type': 'Feature',
'id': 'node/1',
'geometry': {
'type': 'Point',
'coordinates': [
-77.02937206507221,
38.89497324828185
]
},
'properties': {
'id': 'node/1',
'version': 1,
'name': 'Test',
'building': 'yes',
'icon': 'maki_marker'
}
},
id: 'node/1'
}

fetch.resetMocks()
fetch
.once('1') // open changeset
.once('Version mismatch: Provided 1, server had: 2 of Node 1', { status: 409 }) // upload osm change

return store.dispatch(uploadEdits([edit.id]))
.then(() => {
const actions = store.getActions()
expect(actions).toMatchSnapshot()
})
})
})
Loading

0 comments on commit 39ca118

Please sign in to comment.