Skip to content

Commit

Permalink
Merge pull request #5 from digital-land/removeSubmitPage
Browse files Browse the repository at this point in the history
Remove submit page
  • Loading branch information
GeorgeGoodall authored Nov 6, 2023
2 parents 15e3e12 + 24c31fb commit 337ce01
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 64 deletions.
41 changes: 0 additions & 41 deletions src/controllers/submitForm.js

This file was deleted.

35 changes: 32 additions & 3 deletions src/controllers/uploadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,44 @@ const upload = multer({ dest: 'uploads/' })

const { Controller } = require('hmpo-form-wizard')

const { readFile } = require('node:fs/promises')
const { lookup } = require('mime-types')

const apiRoute = 'http://127.0.0.1:8082/api/dataset/validate/file/request/'

class UploadController extends Controller {
middlewareSetup () {
super.middlewareSetup()
this.use('/upload', upload.single('datafile'))
}

post (req, res, next) {
req.body.datafile = req.file
super.post(req, res, next)
async post (req, res, next) {
const formData = new FormData()
formData.append('dataset', req.sessionModel.get('dataset'))
formData.append('collection', req.sessionModel.get('data-subject'))
formData.append('organization', 'mockOrg')

const filePath = req.file.path
const file = new Blob([await readFile(filePath)], { type: lookup(filePath) })

formData.append('upload_file', file, req.file.originalname)

try {
// post the data to the api
const result = await fetch(apiRoute, {
method: 'POST',
body: formData
})

const json = await result.json()

console.log(json)

// send the response back to the user
res.send(json)
} catch (e) {
res.send(e)
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/routes/form-wizard/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports = {
'/upload': {
controller: require('../../controllers/uploadController'),
fields: ['datafile', 'path'],
next: 'submit'
},
'/submit': {
controller: require('../../controllers/submitForm'),
next: 'done'
}
}
4 changes: 0 additions & 4 deletions test/acceptance/pages_load_ok.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ test.describe('without a valid session, the user can not access the later pages'
test('/upload', async ({ page }) => {
await checkSessionExpired(page, '/upload')
})

test('/submit', async ({ page }) => {
await checkSessionExpired(page, '/submit')
})
})
13 changes: 1 addition & 12 deletions test/acceptance/upload_data.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test'
import { test } from '@playwright/test'

test('Upload data', async ({ page }) => {
await page.goto('/')
Expand All @@ -21,15 +21,4 @@ test('Upload data', async ({ page }) => {
const fileChooser = await fileChooserPromise
await fileChooser.setFiles('test/testData/conservation-area.csv')
await page.getByRole('button', { name: 'Continue' }).click()

await page.waitForURL('**/submit')

const ListedDataSubject = await page.getByText('data-subject: Conservation area')
await expect(ListedDataSubject !== undefined).toBeTruthy()

const ListedDataset = await page.getByText('dataset: Conservation area dataset')
await expect(ListedDataset !== undefined).toBeTruthy()

const ListedDatafile = await page.getByText('datafile: conservation-area.csv')
await expect(ListedDatafile !== undefined).toBeTruthy()
})

0 comments on commit 337ce01

Please sign in to comment.