Skip to content

Commit

Permalink
moved createConflict() to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
sadiqkhoja committed Oct 17, 2023
1 parent cc7b970 commit 3fa659b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
3 changes: 2 additions & 1 deletion test/integration/api/projects.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const appRoot = require('app-root-path');
const should = require('should');
const { sql } = require('slonik');
const { testService, createConflict } = require('../setup');
const { testService } = require('../setup');
const testData = require('../../data/xml');
const { QueryOptions } = require('../../../lib/util/db');
const { Actor } = require('../../../lib/model/frames');
const { createConflict } = require('../fixtures/scenarios');
// eslint-disable-next-line import/no-dynamic-require
const { exhaust } = require(appRoot + '/lib/worker/worker');

Expand Down
33 changes: 33 additions & 0 deletions test/integration/fixtures/scenarios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const appRoot = require('app-root-path');
const { exhaust } = require(appRoot + '/lib/worker/worker');
const testData = require('../../data/xml');

const createConflict = async (user, container) => {
await user.post('/v1/projects/1/forms/simpleEntity/submissions')
.send(testData.instances.simpleEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);

await user.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc?force=true')
.send({ data: { age: '99' } })
.expect(200);

await user.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.updateEntity)
.set('Content-Type', 'application/xml')
.expect(200);

// all properties changed
await user.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);
};

module.exports = {
createConflict
};
35 changes: 1 addition & 34 deletions test/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { noop } = require(appRoot + '/lib/util/util');
const { task } = require(appRoot + '/lib/task/task');
const authenticateUser = require('../util/authenticate-user');
const testData = require('../data/xml');
const { exhaust } = require(appRoot + '/lib/worker/worker');

// knex things.
const config = require('config');
Expand Down Expand Up @@ -220,36 +219,4 @@ const withClosedForm = (f) => async (service) => {
return f(service);
};

const createConflict = async (user, container) => {
await user.post('/v1/projects/1/forms/simpleEntity/submissions')
.send(testData.instances.simpleEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);

await user.patch('/v1/projects/1/datasets/people/entities/12345678-1234-4123-8234-123456789abc?force=true')
.send({ data: { age: '99' } })
.expect(200);

await user.post('/v1/projects/1/forms?publish=true')
.send(testData.forms.updateEntity)
.set('Content-Type', 'application/xml')
.expect(200);

// all properties changed
await user.post('/v1/projects/1/forms/updateEntity/submissions')
.send(testData.instances.updateEntity.one)
.set('Content-Type', 'application/xml')
.expect(200);

await exhaust(container);
};

module.exports = {
testService, testServiceFullTrx,
testContainer, testContainerFullTrx,
testTask, withClosedForm,
createConflict
};

module.exports = { testService, testServiceFullTrx, testContainer, testContainerFullTrx, testTask, withClosedForm };

0 comments on commit 3fa659b

Please sign in to comment.