style: apply stricter ts lint rules

This commit is contained in:
Michel Jonathan Schmitz
2019-06-19 16:13:50 +02:00
parent 38f5445634
commit 45755000f3
15 changed files with 145 additions and 104 deletions

128
test/http-client.spec.ts Normal file
View File

@@ -0,0 +1,128 @@
/*
* Copyright (C) 2018 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {expect} from 'chai';
import {suite, test} from 'mocha-typescript';
import * as nock from 'nock';
import {HttpClient} from '../src/http-client';
@suite()
export class HttpClientSpec {
@test
async construct() {
expect(() => {
return new HttpClient();
}).not.to.throw();
}
@test
async request() {
const client = new HttpClient();
nock('http://www.example.com')
.get('/resource')
.reply(200, 'foo');
const response = await client.request({
url: new URL('http://www.example.com/resource'),
});
expect(response.body).to.be.equal('foo');
}
@test
async requestWithBody() {
const client = new HttpClient();
nock('http://www.example.com')
.get('/resource')
.reply(200, 'foo');
const response = await client.request({
body: {
foo: 'bar',
},
url: new URL('http://www.example.com/resource'),
});
expect(response.body).to.be.equal('foo');
}
@test
async requestWithError() {
const client = new HttpClient();
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;
}
@test
async requestWithHeaders() {
const client = new HttpClient();
nock('http://www.example.com')
.get('/resource')
.reply(200, 'foo');
const response = await client.request({
headers: {
'X-StApps-Version': 'foo.bar.foobar',
},
url: new URL('http://www.example.com/resource'),
});
expect(response.body).to.be.equal('foo');
}
@test
async requestWithMethodGet() {
const client = new HttpClient();
nock('http://www.example.com')
.get('/resource')
.reply(200, 'foo');
const response = await client.request({
method: 'GET',
url: new URL('http://www.example.com/resource'),
});
expect(response.body).to.be.equal('foo');
}
@test
async requestWithMethodPost() {
const client = new HttpClient();
nock('http://www.example.com')
.post('/resource')
.reply(200, 'foo');
const response = await client.request({
method: 'POST',
url: new URL('http://www.example.com/resource'),
});
expect(response.body).to.be.equal('foo');
}
}