From 50ace20bc990e192c95901cd771128f0ac5c7391 Mon Sep 17 00:00:00 2001 From: tomlebl Date: Mon, 29 Jul 2024 14:54:48 +0100 Subject: [PATCH] fixing claim tests --- nomad-rest-api/controllers/claim.js | 13 +++++++++---- nomad-rest-api/tests/claim.test.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/nomad-rest-api/controllers/claim.js b/nomad-rest-api/controllers/claim.js index 87a3743..22275fc 100644 --- a/nomad-rest-api/controllers/claim.js +++ b/nomad-rest-api/controllers/claim.js @@ -144,12 +144,17 @@ export const approveClaims = async (req, res) => { req.body.map(async id => { const claim = await Claim.findById(id) const instrument = await Instrument.findById(claim.instrument, 'cost') - const { grantId, multiplier } = await getGrantInfo(claim.user, claim.group) claim.status = 'Approved' - claim.grantCosting = { - grantId, - cost: +claim.expTime * instrument.cost * multiplier + + const grant = await getGrantInfo(claim.user, claim.group) + if (grant) { + const { grantId, multiplier } = grant + + claim.grantCosting = { + grantId, + cost: +claim.expTime * instrument.cost * multiplier + } } await claim.save() diff --git a/nomad-rest-api/tests/claim.test.js b/nomad-rest-api/tests/claim.test.js index 87d2f6e..21bd9b7 100644 --- a/nomad-rest-api/tests/claim.test.js +++ b/nomad-rest-api/tests/claim.test.js @@ -220,7 +220,7 @@ describe('PATCH /', () => { }) describe('PUT /approve', () => { - it('should change status of testClaimRwo to "approve"', async () => { + it('should change status of testClaimTwo to "approve"', async () => { const { body } = await request(app) .put('/claims/approve') .set('Authorization', `Bearer ${testUserAdmin.tokens[0].token}`)