Skip to content

Commit

Permalink
Allowing upgrade and update to be used interchangably in the URLs (to…
Browse files Browse the repository at this point in the history
… support updating the kit).
  • Loading branch information
nataliecarey committed Jul 14, 2023
1 parent dde4af7 commit 066e60c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { replaceInFile, waitForApplication, uninstallPlugin, log } = require('../../utils')
const path = require('path')
const { performPluginAction } = require('../plugin-utils')
const plugin = '@govuk-prototype-kit/task-list'
const pluginVersion = '1.1.1'
const originalText = '"dependencies": {'
const replacementText = `"dependencies": { "${plugin}": "${pluginVersion}",`
const pkgJsonFile = path.join(Cypress.env('projectFolder'), 'package.json')

function restore () {
uninstallPlugin(plugin)
}

describe('Allow upgrade in URLs', () => {
before(restore)
after(restore)

it('When updating the old upgrade URL should still work', () => {
waitForApplication()

log(`Add an old version of ${plugin} within the package.json`)
replaceInFile(pkgJsonFile, originalText, '', replacementText)
cy.exec(`cd ${Cypress.env('projectFolder')} && npm install`)

log('Make sure old upgrade URL still works')
cy.visit(`/manage-prototype/plugins/upgrade?package=${encodeURIComponent(plugin)}`)
cy.get('button#plugin-action-button')
.contains('Update')
.click()

log('Force the plugins to be installed with an npm install')
performPluginAction('update', plugin, 'Task List')
})
})
16 changes: 12 additions & 4 deletions lib/manage-prototype-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ async function getPluginsHandler (req, res) {
async function getPluginForRequest (req) {
const packageName = req.query.package || req.body.package
const version = req.query.version || req.body.version
const { mode } = req.params
const mode = getModeFromRequest(req)
let chosenPlugin

if (packageName) {
Expand Down Expand Up @@ -569,7 +569,7 @@ function modeIsComplete (mode, { installedVersion, latestVersion, version, insta

async function getPluginsModeHandler (req, res) {
const isSameOrigin = req.headers['sec-fetch-site'] === 'same-origin'
const { mode } = req.params
const mode = getModeFromRequest(req)
const { version } = req.query
const verb = verbs[mode]

Expand Down Expand Up @@ -623,8 +623,16 @@ function setKitRestarted (state) {
kitRestarted = state
}

async function postPluginsStatusHandler (req, res) {
function getModeFromRequest (req) {
const { mode } = req.params
if (mode === 'upgrade') {
return 'update'
}
return mode
}

async function postPluginsStatusHandler (req, res) {
const mode = getModeFromRequest(req)
let status = 'processing'
try {
if (kitRestarted) {
Expand Down Expand Up @@ -658,7 +666,7 @@ async function postPluginsModeMiddleware (req, res, next) {
}

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

// Allow smooth update from 13.1.0 as the status route is incorrectly matched
if (mode === 'status') {
Expand Down

0 comments on commit 066e60c

Please sign in to comment.