generated from DEFRA/ffc-template-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from DEFRA/sfi-878-disable-by-scheme
Add UI to disable service by scheme
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const db = require('../data') | ||
|
||
const getPaymentSchemes = async () => { | ||
return db.scheme.findAll() | ||
} | ||
|
||
const updatePaymentScheme = async (schemeId, active) => { | ||
await db.scheme.update({ active }, { where: { schemeId } }) | ||
} | ||
|
||
module.exports = { | ||
getPaymentSchemes, | ||
updatePaymentScheme | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { getPaymentSchemes, updatePaymentScheme } = require('../payment-scheme') | ||
const joi = require('joi') | ||
|
||
module.exports = [{ | ||
method: 'GET', | ||
path: '/payment-schemes', | ||
options: { | ||
handler: async (request, h) => { | ||
const paymentSchemes = await getPaymentSchemes() | ||
return h.response({ | ||
paymentSchemes | ||
}) | ||
} | ||
} | ||
}, | ||
{ | ||
method: 'POST', | ||
path: '/change-payment-status', | ||
options: { | ||
validate: { | ||
payload: joi.object({ | ||
schemeId: joi.number().required(), | ||
active: joi.boolean().required() | ||
}) | ||
}, | ||
handler: async (request, h) => { | ||
await updatePaymentScheme(request.payload.schemeId, request.payload.active) | ||
return h.response('ok').code(200) | ||
} | ||
} | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
const db = require('../../../../app/data') | ||
jest.mock('ffc-messaging') | ||
let createServer | ||
let server | ||
let scheme | ||
|
||
describe('schemes routes', () => { | ||
beforeEach(async () => { | ||
await db.sequelize.truncate({ cascade: true }) | ||
|
||
scheme = { | ||
schemeId: 1, | ||
name: 'SFI', | ||
active: true | ||
} | ||
|
||
createServer = require('../../../../app/server') | ||
server = await createServer() | ||
await server.initialize() | ||
}) | ||
|
||
afterEach(async () => { | ||
await server.stop() | ||
}) | ||
|
||
test('GET /payment-schemes returns schemes', async () => { | ||
const options = { | ||
method: 'GET', | ||
url: '/payment-schemes' | ||
} | ||
|
||
await db.scheme.create(scheme) | ||
|
||
const result = await server.inject(options) | ||
expect(result.statusCode).toBe(200) | ||
}) | ||
|
||
test('POST /change-payment-status changes status to active false', async () => { | ||
const options = { | ||
method: 'POST', | ||
url: '/change-payment-status', | ||
payload: { | ||
schemeId: 1, | ||
active: false | ||
} | ||
} | ||
|
||
await db.scheme.create(scheme) | ||
|
||
const result = await server.inject(options) | ||
const updatedScheme = await db.scheme.findByPk(1) | ||
expect(result.statusCode).toBe(200) | ||
expect(updatedScheme.active).toBeFalsy() | ||
}) | ||
|
||
test('POST /change-payment-status changes status to active', async () => { | ||
const options = { | ||
method: 'POST', | ||
url: '/change-payment-status', | ||
payload: { | ||
schemeId: 1, | ||
active: true | ||
} | ||
} | ||
|
||
scheme.active = false | ||
await db.scheme.create(scheme) | ||
|
||
const result = await server.inject(options) | ||
const updatedScheme = await db.scheme.findByPk(1) | ||
expect(result.statusCode).toBe(200) | ||
expect(updatedScheme.active).toBeTruthy() | ||
}) | ||
}) |