Skip to content

Commit

Permalink
Merge pull request #80 from developmentseed/edit-workflow-tests
Browse files Browse the repository at this point in the history
Edit workflow tests
  • Loading branch information
geohacker authored Jul 9, 2019
2 parents da1aced + 39ca118 commit dbc32da
Show file tree
Hide file tree
Showing 8 changed files with 193,450 additions and 3 deletions.
216 changes: 216 additions & 0 deletions __tests__/actions/__snapshots__/edit.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test async edit actions should UPLOAD_EDITS 1`] = `
Array [
Object {
"edit": Object {
"comment": "Test",
"errors": Array [],
"id": "node/observe-vfxnxtmo20j",
"newFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/observe-vfxnxtmo20j",
"properties": Object {
"building": "yes",
"icon": "maki_marker",
"id": "node/observe-vfxnxtmo20j",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"oldFeature": null,
"status": "pending",
"timestamp": 1562325975841,
"type": "create",
},
"type": "EDIT_UPLOAD_STARTED",
},
Object {
"changesetId": "1",
"edit": Object {
"comment": "Test",
"errors": Array [],
"id": "node/observe-vfxnxtmo20j",
"newFeature": Object {
"geometry": Object {
"coordinates": Array [
-77.02937206507221,
38.89497324828185,
],
"type": "Point",
},
"id": "node/observe-vfxnxtmo20j",
"properties": Object {
"building": "yes",
"icon": "maki_marker",
"id": "node/observe-vfxnxtmo20j",
"name": "Test",
"version": 1,
},
"type": "Feature",
},
"oldFeature": null,
"status": "pending",
"timestamp": 1562325975841,
"type": "create",
},
"timestamp": 1000,
"type": "EDIT_UPLOADED",
},
Object {
"offline": false,
"tile": "0320100322313223",
"type": "REQUESTED_TILE",
},
Object {
"tile": "0320100322313223",
"type": "LOADING_DATA_FOR_TILE",
},
Object {
"offline": false,
"tile": "0320100322313223",
"type": "LOADED_DATA_FOR_TILE",
},
Object {
"type": "UPDATE_VISIBLE_BOUNDS",
"visibleBounds": Array [
Array [
-77.02886915086447,
38.8957164152211,
],
Array [
-77.02987497924005,
38.8942300735456,
],
],
"zoom": 18,
},
Object {
"offline": false,
"tile": "0320100322313221",
"type": "REQUESTED_TILE",
},
Object {
"offline": false,
"tile": "0320100322313223",
"type": "REQUESTED_TILE",
},
]
`;

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",
},
]
`;
99 changes: 98 additions & 1 deletion __tests__/actions/edit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import {
setAddPointGeometry,
startEditUpload,
editUploadFailed,
editUploaded
editUploaded,
uploadEdits
} from '../../app/actions/edit'
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 @@ -130,3 +135,95 @@ describe('test sync edit actions', () => {
})
})
})

describe('test async edit actions', () => {
it('should UPLOAD_EDITS', () => {
const store = mockStore(state)
const edit = {
oldFeature: null,
newFeature: { 'type': 'Feature', 'id': 'node/observe-vfxnxtmo20j', 'geometry': { 'type': 'Point', 'coordinates': [-77.02933996149397, 38.89503041477742] }, 'properties': { 'id': 'node/observe-vfxnxtmo20j', 'version': 1, 'name': 'Test', 'building': 'yes', 'icon': 'maki_marker' } },
id: 'node/observe-vfxnxtmo20j'
}
const xmlDiffResponse = fs.readFileSync(path.join(__dirname, '../fixtures/osm-change-upload-response.xml'), 'utf-8')
const osmResponseforTileUpdate = fs.readFileSync(path.join(__dirname, '../fixtures/osm-response-for-updated-tile.xml'), 'utf-8')

fetch
.once('1') // open changeset
.once(xmlDiffResponse) // upload osm change
.once({ status: 200 }) // close changeset
.once(osmResponseforTileUpdate)

return store.dispatch(uploadEdits([edit.id]))
.then(() => {
const actions = store.getActions()
const types = []
actions.forEach(action => {
types.push(action.type)
})
expect(types).toStrictEqual([ 'EDIT_UPLOAD_STARTED',
'EDIT_UPLOADED',
'REQUESTED_TILE',
'LOADING_DATA_FOR_TILE',
'LOADED_DATA_FOR_TILE',
'UPDATE_VISIBLE_BOUNDS',
'REQUESTED_TILE',
'REQUESTED_TILE' ])

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()
})
})
})
4 changes: 4 additions & 0 deletions __tests__/fixtures/osm-change-upload-response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<diffResult version="0.6" generator="CGImap 0.7.5 (31866 errol.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node old_id="-1" new_id="4318103827" new_version="1"/>
</diffResult>
Loading

0 comments on commit dbc32da

Please sign in to comment.