Archived
2

base for csv export

This commit is contained in:
VLE2FE
2020-06-29 12:27:39 +02:00
parent 8aa051f0bd
commit e5cc661928
10 changed files with 87 additions and 17 deletions

View File

@ -38,15 +38,7 @@ export default class TestHelper {
return server
}
static afterEach (server, done) {
server.close(done);
}
static after(done) {
db.disconnect(done);
}
static request (server, done, options) { // options in form: {method, url, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res, default (set to false if you want to dismiss default .end handling)}
static request (server, done, options) { // options in form: {method, url, contentType, auth: {key/basic: 'name' or 'key'/{name, pass}}, httpStatus, req, res, default (set to false if you want to dismiss default .end handling)}
let st = supertest(server);
if (options.hasOwnProperty('auth') && options.auth.hasOwnProperty('key')) { // resolve API key
options.url += '?key=' + (this.auth.hasOwnProperty(options.auth.key)? this.auth[options.auth.key].key : options.auth.key);
@ -79,8 +71,12 @@ export default class TestHelper {
st = st.auth(options.auth.basic.name, options.auth.basic.pass)
}
}
st = st.expect('Content-type', /json/)
.expect(options.httpStatus);
if (options.hasOwnProperty('contentType')) {
st = st.expect('Content-type', options.contentType).expect(options.httpStatus);
}
else {
st = st.expect('Content-type', /json/).expect(options.httpStatus);
}
if (options.hasOwnProperty('res')) { // evaluate result
return st.end((err, res) => {
if (err) return done (err);
@ -128,4 +124,12 @@ export default class TestHelper {
return st;
}
}
static afterEach (server, done) {
server.close(done);
}
static after(done) {
db.disconnect(done);
}
}