Skip to content

Commit

Permalink
Less test hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
flurdy committed May 14, 2024
1 parent f005d7b commit b55936d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 49 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"scripts": {
"clean": "rm -rf allure-results && rm -rf allure-report",
"test:local:debug": "DEBUG=true npm run test:local",
"testc": "TZ=UTC npm run clean && jest --coverage --verbose",
"testc:watch": "TZ=UTC npm run clean && jest --watch",
"test": "TZ=UTC jest --coverage --verbose",
"test": "TZ=UTC npm run clean && jest --verbose",
"test:dirty": "TZ=UTC jest --verbose",
"test:watch": "TZ=UTC jest --watch .js",
"format": "prettier --write 'src/**/*.js' '**/*.{js,md,json,config.js}'",
"format:check": "prettier --check 'src/**/*.js' '**/*.{js,md,json,config.js}'",
Expand Down
6 changes: 0 additions & 6 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ const config = convict({
default: 30,
env: 'UPLOAD_MAX_ATTEMPTS'
},
uploadOnlyTimeout: {
doc: 'How long to poll for upload initial completion',
format: Number,
default: 1000 * 20,
env: 'UPLOAD_ONLY_TIMEOUT'
},
uploadScanTimeout: {
doc: 'How long to poll for scan completion',
format: Number,
Expand Down
73 changes: 33 additions & 40 deletions src/test/specs/upload-file/upload-journey.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {

const uploaderBaseUrl = config.get('uploaderBaseUrl')
const cleanFilename = config.get('cleanFileName')
const uploadTimeout = config.get('uploadOnlyTimeout')
const scanTimeout = config.get('uploadScanTimeout')
const redirectUrl = config.get('redirectUrl')

describe('CDP File uploader Smoke Test', () => {
jest.setTimeout(scanTimeout)

it('should initiate a file upload', async () => {
const { uploadId, uploadUrl, statusUrl } = await initiateWithPayload()
expect(validate(uploadId)).toBeTruthy()
Expand All @@ -26,46 +27,38 @@ describe('CDP File uploader Smoke Test', () => {
expect(uploadDetails.uploadStatus).toEqual('initiated')
})

describe('Start file upload journey', () => {
jest.setTimeout(uploadTimeout)

it('should upload a file', async () => {
const { uploadId, uploadStatusCode, statusUrl, location } =
await cleanFileUpload()
expect(uploadStatusCode).toEqual(302)
expect(location).toEqual(`${redirectUrl}?uploadId=${uploadId}`)
const { uploadStatus, fileDetails } = await findFileDetails(statusUrl)
expect(uploadStatus).toBeDefined()
expect(fileDetails?.fileStatus).toBeDefined()
expect(validate(fileDetails.fileId)).toBeTruthy()
expect(fileDetails.filename).toEqual(cleanFilename)
// Virus scanning may already be complete
expect(['pending', 'ready']).toContain(uploadStatus)
expect(['pending', 'complete']).toContain(fileDetails.fileStatus)
})

describe('Checking file scanning', () => {
jest.setTimeout(scanTimeout)
it('should upload a file', async () => {
const { uploadId, uploadStatusCode, statusUrl, location } =
await cleanFileUpload()
expect(uploadStatusCode).toEqual(302)
expect(location).toEqual(`${redirectUrl}?uploadId=${uploadId}`)
const { uploadStatus, fileDetails } = await findFileDetails(statusUrl)
expect(uploadStatus).toBeDefined()
expect(fileDetails?.fileStatus).toBeDefined()
expect(validate(fileDetails.fileId)).toBeTruthy()
expect(fileDetails.filename).toEqual(cleanFilename)
// Virus scanning may already be complete
expect(['pending', 'ready']).toContain(uploadStatus)
expect(['pending', 'complete']).toContain(fileDetails.fileStatus)
})

it('should get scanned as clean', async () => {
const { statusUrl } = await cleanFileUpload()
const { isUploadReady } = await findFileDetailsWhenReady(statusUrl)
expect(isUploadReady).toBeTruthy()
const { uploadStatus, fileDetails } = await findFileDetails(statusUrl)
expect(uploadStatus).toEqual('ready')
expect(fileDetails.fileStatus).toEqual('complete')
})
it('should scan file as clean', async () => {
const { statusUrl } = await cleanFileUpload()
const { isUploadReady } = await findFileDetailsWhenReady(statusUrl)
expect(isUploadReady).toBeTruthy()
const { uploadStatus, fileDetails } = await findFileDetails(statusUrl)
expect(uploadStatus).toEqual('ready')
expect(fileDetails.fileStatus).toEqual('complete')
})

it('should get rejected as infected', async () => {
const { statusUrl } = await virusFileUpload()
const { isUploadReady } = await findFileDetailsWhenReady(statusUrl)
expect(isUploadReady).toBeTruthy()
const { uploadStatus, rejectedFiles, fileDetails } =
await findFileDetails(statusUrl)
expect(uploadStatus).toEqual('ready')
expect(fileDetails.fileStatus).toEqual('rejected')
expect(rejectedFiles).toBe(1)
})
})
it('should reject file as infected', async () => {
const { statusUrl } = await virusFileUpload()
const { isUploadReady } = await findFileDetailsWhenReady(statusUrl)
expect(isUploadReady).toBeTruthy()
const { uploadStatus, rejectedFiles, fileDetails } =
await findFileDetails(statusUrl)
expect(uploadStatus).toEqual('ready')
expect(fileDetails.fileStatus).toEqual('rejected')
expect(rejectedFiles).toBe(1)
})
})

0 comments on commit b55936d

Please sign in to comment.