2022-02-15 17:53:02 +00:00
|
|
|
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
2017-01-28 23:51:47 +00:00
|
|
|
|
2022-07-28 23:19:50 +00:00
|
|
|
import * as smartrequest from '../ts/index.js';
|
2017-01-28 23:51:47 +00:00
|
|
|
|
2017-06-09 19:48:16 +00:00
|
|
|
tap.test('should request a html document over https', async () => {
|
2022-02-15 17:57:42 +00:00
|
|
|
await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body');
|
2018-06-13 20:34:49 +00:00
|
|
|
});
|
2017-01-28 23:51:47 +00:00
|
|
|
|
2017-06-09 19:48:16 +00:00
|
|
|
tap.test('should request a JSON document over https', async () => {
|
2022-02-15 17:53:02 +00:00
|
|
|
await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
|
|
|
|
.property('body')
|
2018-06-13 20:34:49 +00:00
|
|
|
.property('id')
|
2022-02-15 17:53:02 +00:00
|
|
|
.toEqual(1);
|
2018-06-13 20:34:49 +00:00
|
|
|
});
|
2017-01-28 23:51:47 +00:00
|
|
|
|
2023-04-19 12:38:28 +00:00
|
|
|
tap.test('should post a JSON document over http', async () => {
|
2022-02-15 17:53:02 +00:00
|
|
|
await expectAsync(smartrequest.postJson('http://md5.jsontest.com/?text=example_text'))
|
|
|
|
.property('body')
|
2018-06-13 20:34:49 +00:00
|
|
|
.property('md5')
|
2022-02-15 17:53:02 +00:00
|
|
|
.toEqual('fa4c6baa0812e5b5c80ed8885e55a8a6');
|
2018-06-13 20:34:49 +00:00
|
|
|
});
|
2017-06-09 19:48:16 +00:00
|
|
|
|
2023-04-19 12:38:28 +00:00
|
|
|
tap.test('should safe get stuff', async () => {
|
|
|
|
smartrequest.safeGet('http://coffee.link/');
|
|
|
|
smartrequest.safeGet('https://coffee.link/');
|
|
|
|
});
|
|
|
|
|
2018-07-16 21:51:31 +00:00
|
|
|
tap.skip.test('should deal with unix socks', async () => {
|
2018-08-13 23:47:54 +00: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 21:49:35 +00:00
|
|
|
}
|
2018-08-13 23:47:54 +00:00
|
|
|
);
|
2018-07-16 21:39:25 +00:00
|
|
|
console.log(socketResponse.body);
|
2018-07-15 22:38:24 +00:00
|
|
|
});
|
2018-07-15 21:21:07 +00:00
|
|
|
|
2018-08-13 23:47:54 +00:00
|
|
|
tap.skip.test('should correctly upload a file using formData', async () => {});
|
2018-07-19 20:36:45 +00:00
|
|
|
|
2018-07-16 21:51:31 +00:00
|
|
|
tap.start();
|