feat(docs): Enhance documentation and tests with modern API usage examples and migration guide
This commit is contained in:
45
test/test.legacy.ts
Normal file
45
test/test.legacy.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { tap, expect, expectAsync } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartrequest from '../ts/legacy/index.js';
|
||||
|
||||
tap.test('should request a html document over https', async () => {
|
||||
await expectAsync(smartrequest.getJson('https://encrypted.google.com/')).toHaveProperty('body');
|
||||
});
|
||||
|
||||
tap.test('should request a JSON document over https', async () => {
|
||||
await expectAsync(smartrequest.getJson('https://jsonplaceholder.typicode.com/posts/1'))
|
||||
.property('body')
|
||||
.property('id')
|
||||
.toEqual(1);
|
||||
});
|
||||
|
||||
tap.test('should post a JSON document over http', async () => {
|
||||
const testData = { text: 'example_text' };
|
||||
await expectAsync(smartrequest.postJson('https://httpbin.org/post', { requestBody: testData }))
|
||||
.property('body')
|
||||
.property('json')
|
||||
.property('text')
|
||||
.toEqual('example_text');
|
||||
});
|
||||
|
||||
tap.test('should safe get stuff', async () => {
|
||||
smartrequest.safeGet('http://coffee.link/');
|
||||
smartrequest.safeGet('https://coffee.link/');
|
||||
});
|
||||
|
||||
tap.skip.test('should deal with unix socks', async () => {
|
||||
const socketResponse = await smartrequest.request(
|
||||
'http://unix:/var/run/docker.sock:/containers/json',
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Host: 'docker.sock',
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log(socketResponse.body);
|
||||
});
|
||||
|
||||
tap.skip.test('should correctly upload a file using formData', async () => {});
|
||||
|
||||
tap.start();
|
Reference in New Issue
Block a user