Skip to content

Commit

Permalink
Merge pull request #20 from DEFRA/sfi-878-disable-by-scheme
Browse files Browse the repository at this point in the history
Add UI to disable service by scheme
  • Loading branch information
FayToward authored Sep 7, 2021
2 parents 32aadb4 + 0f8efce commit 4f32ebc
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/payment-scheme/index.js
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
}
1 change: 1 addition & 0 deletions app/plugins/router.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const routes = [].concat(
require('../routes/healthy'),
require('../routes/healthz'),
require('../routes/payment-schemes'),
require('../routes/holds')
)

Expand Down
31 changes: 31 additions & 0 deletions app/routes/payment-schemes.js
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)
}
}
}]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffc-sfi-payments",
"version": "2.4.0",
"version": "2.5.0",
"description": "FFC SFI payment services",
"homepage": "https://github.com/DEFRA/ffc-sfi-payments",
"main": "app/index.js",
Expand Down
74 changes: 74 additions & 0 deletions test/integration/narrow/holds/get-schemes.test.js
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()
})
})

0 comments on commit 4f32ebc

Please sign in to comment.