smartrequest/test/test.ts

39 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-02-15 18:53:02 +01:00
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
2017-01-29 00:51:47 +01:00
2018-06-13 22:34:49 +02:00
import * as smartrequest from '../ts/index';
2017-01-29 00:51:47 +01:00
2017-06-09 21:48:16 +02:00
tap.test('should request a html document over https', async () => {
2022-02-15 18:57:42 +01:00
await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body');
2018-06-13 22:34:49 +02:00
});
2017-01-29 00:51:47 +01:00
2017-06-09 21:48:16 +02:00
tap.test('should request a JSON document over https', async () => {
2022-02-15 18:53:02 +01:00
await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
.property('body')
2018-06-13 22:34:49 +02:00
.property('id')
2022-02-15 18:53:02 +01:00
.toEqual(1);
2018-06-13 22:34:49 +02:00
});
2017-01-29 00:51:47 +01:00
2019-09-29 00:42:51 +02:00
tap.skip.test('should post a JSON document over http', async () => {
2022-02-15 18:53:02 +01:00
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
.property('body')
2018-06-13 22:34:49 +02:00
.property('md5')
2022-02-15 18:53:02 +01:00
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
2018-06-13 22:34:49 +02:00
});
2017-06-09 21:48:16 +02:00
2018-07-16 23:51:31 +02:00
tap.skip.test('should deal with unix socks', async () => {
2018-08-14 01:47:54 +02:00
const socketResponse = await smartrequest.request(
'http://unix:/var/run/docker.sock:/containers/json',
{
headers: {
'Content-Type': 'application/json',
2020-08-24 12:01:38 +00:00
Host: 'docker.sock',
},
2018-07-16 23:49:35 +02:00
}
2018-08-14 01:47:54 +02:00
);
2018-07-16 23:39:25 +02:00
console.log(socketResponse.body);
2018-07-16 00:38:24 +02:00
});
2018-08-14 01:47:54 +02:00
tap.skip.test('should correctly upload a file using formData', async () => {});
2018-07-19 22:36:45 +02:00
2018-07-16 23:51:31 +02:00
tap.start();