mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-09 19:22:51 +00:00
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 StApps
|
||||
* Copyright (C) 2018-2020 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
@@ -17,6 +17,8 @@ import {suite, test} from '@testdeck/mocha';
|
||||
import nock from 'nock';
|
||||
import {HttpClient} from '../src/http-client';
|
||||
|
||||
// TODO: use after each to clean up the nock (then there is no need for numerated resource links)
|
||||
|
||||
@suite()
|
||||
export class HttpClientSpec {
|
||||
|
||||
@@ -27,6 +29,10 @@ export class HttpClientSpec {
|
||||
}).not.to.throw();
|
||||
}
|
||||
|
||||
async after() {
|
||||
nock.cleanAll();
|
||||
}
|
||||
|
||||
@test
|
||||
async request() {
|
||||
const client = new HttpClient();
|
||||
@@ -51,10 +57,7 @@ export class HttpClientSpec {
|
||||
.reply(200, 'foo');
|
||||
|
||||
const response = await client.request({
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
url: new URL('http://www.example.com/resource'),
|
||||
url: new URL('http://www.example.com/resource')
|
||||
});
|
||||
|
||||
expect(response.body).to.be.equal('foo');
|
||||
@@ -63,17 +66,24 @@ export class HttpClientSpec {
|
||||
@test
|
||||
async requestWithError() {
|
||||
const client = new HttpClient();
|
||||
let caughtErr;
|
||||
|
||||
nock('http://www.example.com')
|
||||
.get('/resource')
|
||||
.replyWithError('foo');
|
||||
|
||||
return client.request({
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
url: new URL('http://www.example.com/resource'),
|
||||
}).should.be.rejected;
|
||||
try {
|
||||
await client.request({
|
||||
body: {
|
||||
foo: 'bar',
|
||||
},
|
||||
url: new URL('http://www.example.com/resource'),
|
||||
});
|
||||
} catch (err) {
|
||||
caughtErr = err;
|
||||
}
|
||||
|
||||
expect(caughtErr).not.to.be.undefined;
|
||||
}
|
||||
|
||||
@test
|
||||
|
||||
Reference in New Issue
Block a user