-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make sure deleting an app works
- Loading branch information
Erik
authored and
Erik A
committed
Mar 4, 2020
1 parent
8ae3787
commit 1be1d7e
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const Lab = require('@hapi/lab') | ||
|
||
const { it, describe, beforeEach, afterEach } = (exports.lab = Lab.script()) | ||
|
||
const { expect } = require('@hapi/code') | ||
|
||
const knexConfig = require('../../knexfile') | ||
const db = require('knex')(knexConfig) | ||
|
||
const { init } = require('../../src/server/init-server') | ||
|
||
const users = require('../../seeds/mock/users') | ||
|
||
describe('test delete app', () => { | ||
const { config } = require('../../src/server/noauth-config') | ||
let server | ||
beforeEach(async () => { | ||
config.auth.noAuthUserIdMapping = users[0].id | ||
server = await init(db, config) | ||
}) | ||
|
||
afterEach(async () => { | ||
await server.stop() | ||
}) | ||
|
||
const sampleApp = { | ||
name: 'DHIS2 Sample App', | ||
description: 'A very nice sample description', | ||
appType: 'APP', | ||
sourceUrl: 'http://github.com', | ||
developer: { | ||
name: 'Foo Bar', | ||
email: '[email protected]', | ||
address: '', | ||
organisation: 'The Largest Testing Organization In The World.', | ||
}, | ||
versions: [ | ||
{ | ||
version: '1', | ||
minDhisVersion: '2.25', | ||
maxDhisVersion: '2.33', | ||
demoUrl: 'https://www.dhis2.org', | ||
channel: 'Stable', | ||
}, | ||
], | ||
images: [], | ||
} | ||
|
||
it('should be able to delete an app', async () => { | ||
//First upload the app, then delete it | ||
const fs = require('fs') | ||
const path = require('path') | ||
const request = require('request-promise') | ||
|
||
const form = { | ||
app: JSON.stringify(sampleApp), | ||
file: { | ||
value: fs.createReadStream( | ||
path.join(__dirname, '../', 'sample-app.zip') | ||
), | ||
options: { | ||
filename: 'sample-app.zip', | ||
contentType: 'application/zip', | ||
}, | ||
}, | ||
} | ||
|
||
const response = await request.post({ | ||
url: `http://${server.settings.host}:${server.settings.port}/api/apps`, | ||
json: true, | ||
formData: form, | ||
}) | ||
expect(response.statusCode).to.equal(200) | ||
|
||
const appId = response.uuid | ||
const deleteResponse = await server.inject({ | ||
method: 'DELETE', | ||
url: '/api/v1/apps/' + appId, | ||
}) | ||
|
||
expect(deleteResponse.statusCode).to.equal(200) | ||
}) | ||
}) |