Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove submit page #5

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})