@autofleet/network 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -2
- package/package.json +1 -1
- package/.github/workflows/main.yml +0 -25
- package/index.test.js +0 -69
- package/jest.config.js +0 -8
package/index.js
CHANGED
|
@@ -82,6 +82,7 @@ module.exports = class Network {
|
|
|
82
82
|
headers: request.headers,
|
|
83
83
|
query: request.query,
|
|
84
84
|
body: request.body,
|
|
85
|
+
params: request.params,
|
|
85
86
|
});
|
|
86
87
|
return request;
|
|
87
88
|
});
|
|
@@ -124,11 +125,11 @@ module.exports = class Network {
|
|
|
124
125
|
async getAllPages(url, options = {}) {
|
|
125
126
|
let currentResult = [];
|
|
126
127
|
let resultsInFirstPage = null;
|
|
127
|
-
let lastResultsSize =
|
|
128
|
+
let lastResultsSize = null;
|
|
128
129
|
|
|
129
130
|
const localOptions = { params: {}, ...options };
|
|
130
131
|
localOptions.params.page = 1;
|
|
131
|
-
while(localOptions.params.page === 1 || lastResultsSize === resultsInFirstPage) {
|
|
132
|
+
while((localOptions.params.page === 1 || lastResultsSize === resultsInFirstPage) && lastResultsSize !== 0) {
|
|
132
133
|
const { data } = await this.get(url, localOptions);
|
|
133
134
|
lastResultsSize = data.length;
|
|
134
135
|
if(localOptions.params.page === 1) {
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Publish Package
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches: [ master ]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
publish-npm:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
steps:
|
|
14
|
-
- uses: actions/checkout@v2
|
|
15
|
-
- uses: actions/setup-node@v1
|
|
16
|
-
with:
|
|
17
|
-
node-version: 12
|
|
18
|
-
registry-url: https://registry.npmjs.org/
|
|
19
|
-
- run: npm i
|
|
20
|
-
env:
|
|
21
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
22
|
-
- run: npm publish --dry-run
|
|
23
|
-
- run: npm publish
|
|
24
|
-
env:
|
|
25
|
-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
package/index.test.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const nock = require('nock');
|
|
2
|
-
const Network = require('./index');
|
|
3
|
-
|
|
4
|
-
nock('http://www.google.com')
|
|
5
|
-
.get('/resource')
|
|
6
|
-
.reply(200, { one: 1 });
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
nock('https://www.apple.com')
|
|
10
|
-
.get('/resource')
|
|
11
|
-
.reply(200, { two: 2 });
|
|
12
|
-
|
|
13
|
-
describe('Network', () => {
|
|
14
|
-
it('Making requests by service name from ENV', async () => {
|
|
15
|
-
process.env.TEST_SERVICE_HOST = 'www.google.com';
|
|
16
|
-
const n = new Network({ serviceName: 'TEST' });
|
|
17
|
-
const response = await n.get('/resource');
|
|
18
|
-
expect(response).toBeDefined();
|
|
19
|
-
expect(response.data).toBeDefined();
|
|
20
|
-
expect(response.data.one).toBe(1);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('Making requests by service name from url', async () => {
|
|
24
|
-
const n = new Network({ serviceUrl: 'https://www.apple.com' });
|
|
25
|
-
const response = await n.get('/resource');
|
|
26
|
-
expect(response).toBeDefined();
|
|
27
|
-
expect(response.data).toBeDefined();
|
|
28
|
-
expect(response.data.two).toBe(2);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('Getting 404', async () => {
|
|
32
|
-
const n = new Network({ serviceUrl: 'https://www.apple.com' });
|
|
33
|
-
|
|
34
|
-
const action = async () => n.get('/resource', {
|
|
35
|
-
query: {
|
|
36
|
-
a: 'b',
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(action()).rejects.toThrow(Error);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('Retry 1 time', async () => {
|
|
44
|
-
nock('https://www.apple2.com')
|
|
45
|
-
.get('/resource')
|
|
46
|
-
.once()
|
|
47
|
-
.reply(500);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
nock('https://www.apple2.com')
|
|
51
|
-
.get('/resource')
|
|
52
|
-
.once()
|
|
53
|
-
.reply(200, { two: 2 });
|
|
54
|
-
|
|
55
|
-
const n = new Network({ serviceUrl: 'https://www.apple2.com' });
|
|
56
|
-
const response = await n.get('/resource', {
|
|
57
|
-
query: {
|
|
58
|
-
a: 'b',
|
|
59
|
-
},
|
|
60
|
-
'axios-retry': {
|
|
61
|
-
retries: 1,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
expect(response).toBeDefined();
|
|
66
|
-
expect(response.data).toBeDefined();
|
|
67
|
-
expect(response.data.two).toBe(2);
|
|
68
|
-
});
|
|
69
|
-
});
|