Skip to content

Commit

Permalink
Merge pull request #1942 from alphagov/allow-smooth-upgrade-from-13-1…
Browse files Browse the repository at this point in the history
…-0-to-13-2-4

Allow smooth upgrade from 13.1.0 to 13.2.4
  • Loading branch information
BenSurgisonGDS authored Jan 27, 2023
2 parents 60cbeec + 67de7c2 commit 3291419
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- [#1942: Allow smooth upgrade from 13.1.0 to 13.2.4](https://github.com/alphagov/govuk-prototype-kit/pull/1942)

## 13.2.3

### Fixes
Expand Down
2 changes: 2 additions & 0 deletions lib/assets/javascripts/manage-prototype/manage-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ window.GOVUKPrototypeKit.documentReady(() => {
if (timedOut) {
showErrorStatus()
} else {
// Be aware that changing this path for monitoring the status of a plugin will affect the
// kit upgrade process as the browser request and server route would be out of sync.
postRequest(`/manage-prototype/plugins/${mode}/status`)
.then(response => response.json())
.then(data => {
Expand Down
7 changes: 7 additions & 0 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ async function postPluginsModeMiddleware (req, res, next) {

async function postPluginsModeHandler (req, res) {
const { mode } = req.params

// Allow smooth upgrade from 13.1.0 as the status route is incorrectly matched
if (mode === 'status') {
req.params.mode = 'upgrade'
return postPluginsStatusHandler(req, res)
}

const verb = verbs[mode]

if (!verb) {
Expand Down
16 changes: 16 additions & 0 deletions lib/manage-prototype-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,22 @@ describe('manage-prototype-handlers', () => {
})
)
})

it('is passed on to the postPluginsStatusHandler when status matches mode during upgrade from 13.1 to 13.2.4 and upwards', async () => {
plugins.listInstalledPlugins.mockReturnValue([packageName])
req.params.mode = 'status'

await postPluginsModeHandler(req, res)

// req.params.mode should change to upgrade
expect(req.params.mode).toEqual('upgrade')

expect(res.json).toHaveBeenCalledWith(
expect.objectContaining({
status: 'completed'
})
)
})
})
})
})
2 changes: 2 additions & 0 deletions lib/manage-prototype-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ router.get('/templates/post-install', getTemplatesPostInstallHandler)

router.get('/plugins', getPluginsHandler)

// Be aware that changing this path for monitoring the status of a plugin will affect the
// kit upgrade process as the browser request and server route would be out of sync.
router.post('/plugins/:mode/status', postPluginsStatusHandler)

router.get('/plugins/:mode', csrfProtection, getPluginsModeHandler)
Expand Down

0 comments on commit 3291419

Please sign in to comment.