diff --git a/packages/component-fixture-manager/src/fixtures/collections.js b/packages/component-fixture-manager/src/fixtures/collections.js index 84583485feff68c50c532e4a5f4a396147177df2..e9d29ef190c37c9b4a43c9536c737f2c17167505 100644 --- a/packages/component-fixture-manager/src/fixtures/collections.js +++ b/packages/component-fixture-manager/src/fixtures/collections.js @@ -46,6 +46,48 @@ const collections = { }, status: 'pendingApproval', }, + collection1: { + id: standardCollID, + title: chance.sentence(), + type: 'collection', + fragments: [fragment.id], + owners: [user.id], + save: jest.fn(() => collections.collection), + invitations: [ + { + id: chance.guid(), + role: 'handlingEditor', + hasAnswer: false, + isAccepted: false, + userId: handlingEditor.id, + invitedOn: chance.timestamp(), + respondedOn: null, + }, + { + id: chance.guid(), + role: 'handlingEditor', + hasAnswer: true, + isAccepted: false, + userId: answerHE.id, + invitedOn: chance.timestamp(), + respondedOn: chance.timestamp(), + }, + ], + handlingEditor: { + id: handlingEditor.id, + hasAnswer: false, + isAccepted: false, + email: handlingEditor.email, + invitedOn: chance.timestamp(), + respondedOn: null, + name: `${handlingEditor.firstName} ${handlingEditor.lastName}`, + }, + customId: '1234568', + technicalChecks: { + token: chance.guid(), + }, + status: 'pendingApproval', + }, } module.exports = collections diff --git a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js index dbc44b3e8326a616c349a8cd06843fc72956f8b2..4afb91c9d628e6a13e19bfea7d2360527dab8ab5 100644 --- a/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js +++ b/packages/component-manuscript-manager/src/routes/technicalChecks/patch.js @@ -25,16 +25,18 @@ module.exports = ({ Collection, Fragment, User }) => async (req, res) => { const collection = await Collection.find(collectionId) const technicalCheckToken = get(collection, `technicalChecks.token`) - if (!customId) { - return res.status(400).json({ - error: 'A manuscript ID is required.', - }) - } + if (step === TECHNICAL_STEPS.EQS) { + if (agree && !customId) { + return res.status(400).json({ + error: 'A manuscript ID is required.', + }) + } - if (find(collections, c => c.customId === customId)) { - return res.status(400).json({ - error: `CustomID already assigned to a manuscript.`, - }) + if (agree && find(collections, c => c.customId === customId)) { + return res.status(400).json({ + error: `CustomID already assigned to a manuscript.`, + }) + } } if (isEmpty(technicalCheckToken)) { diff --git a/packages/component-manuscript-manager/src/tests/technicalChecks/patch.test.js b/packages/component-manuscript-manager/src/tests/technicalChecks/patch.test.js index 224fb99d8bbcd70d97be22a771ee4087b491ea7c..3ec4aa921a652d928a5beb0038781f06e14f9b15 100644 --- a/packages/component-manuscript-manager/src/tests/technicalChecks/patch.test.js +++ b/packages/component-manuscript-manager/src/tests/technicalChecks/patch.test.js @@ -1,4 +1,3 @@ -/* eslint-disable */ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' process.env.SUPPRESS_NO_CONFIG_WARNING = true @@ -14,13 +13,14 @@ jest.mock('@pubsweet/component-send-email', () => ({ const reqBody = { step: 'eqs', agree: true, + customId: '1234567', } const path = '../routes/technicalChecks/patch' const route = { path: '/api/collections/:collectionId/status', } -describe.skip('Patch technical checks route handler', () => { +describe('Patch technical checks route handler', () => { let testFixtures = {} let body = {} let models @@ -30,10 +30,49 @@ describe.skip('Patch technical checks route handler', () => { models = Model.build(testFixtures) }) - it.only('should return success when the EQS is accepted', async () => { + it('should return error when no customId is provided', async () => { + const { collection } = testFixtures.collections + body.token = collection.technicalChecks.token + delete body.customId + const res = await requests.sendRequest({ + body, + models, + route, + path, + params: { + collectionId: collection.id, + }, + }) + + expect(res.statusCode).toBe(400) + expect(res._getData()).toBe( + JSON.stringify({ error: 'A manuscript ID is required.' }), + ) + }) + + it('should return error when a customId already exists', async () => { + const { collection } = testFixtures.collections + body.token = collection.technicalChecks.token + body.customId = '1234568' + const res = await requests.sendRequest({ + body, + models, + route, + path, + params: { + collectionId: collection.id, + }, + }) + + expect(res.statusCode).toBe(400) + expect(res._getData()).toBe( + JSON.stringify({ error: 'CustomID already assigned to a manuscript.' }), + ) + }) + + it('should return success when EQS is accepted', async () => { const { collection } = testFixtures.collections body.token = collection.technicalChecks.token - console.log('testFixture: ', collection) const res = await requests.sendRequest({ body, models, @@ -41,12 +80,11 @@ describe.skip('Patch technical checks route handler', () => { path, params: { collectionId: collection.id, - // customId: '123', }, }) - console.log(res._getData()) expect(res.statusCode).toBe(200) + expect(JSON.parse(res._getData()).customId).toBe('1234567') }) it('should return success when the EQS is rejected', async () => { @@ -63,8 +101,8 @@ describe.skip('Patch technical checks route handler', () => { collectionId: collection.id, }, }) - expect(res.statusCode).toBe(200) + expect(JSON.parse(res._getData()).status).toBe('rejected') }) it('should return success when the EQA is accepted', async () => {