sr-npm 1.7.388 → 1.7.390
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.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
3
|
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
|
-
const secretsData = require('./secretsData');
|
|
5
4
|
async function makeSmartRecruitersRequest(path) {
|
|
6
5
|
const baseUrl = 'https://api.smartrecruiters.com';
|
|
7
6
|
const fullUrl = `${baseUrl}${path}`;
|
|
@@ -28,12 +27,16 @@ async function makeSmartRecruitersRequest(path) {
|
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
async function fetchPositionsFromSRAPI() {
|
|
30
|
+
async function fetchPositionsFromSRAPI(companyID=undefined) {
|
|
32
31
|
let allPositions = [];
|
|
33
32
|
let totalFound = 0;
|
|
34
33
|
let page = 0;
|
|
35
34
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
36
|
-
|
|
35
|
+
let companyId=companyID
|
|
36
|
+
if(!companyID)
|
|
37
|
+
{
|
|
38
|
+
companyId = await getCompanyIdFromCMS();
|
|
39
|
+
}
|
|
37
40
|
console.log('Starting to fetch all positions with pagination...');
|
|
38
41
|
let offset=0;
|
|
39
42
|
|
|
@@ -112,5 +115,6 @@ async function getCompanyIdFromCMS() {
|
|
|
112
115
|
module.exports = {
|
|
113
116
|
fetchPositionsFromSRAPI,
|
|
114
117
|
fetchJobDescription,
|
|
115
|
-
getCompanyIdFromCMS
|
|
118
|
+
getCompanyIdFromCMS,
|
|
119
|
+
makeSmartRecruitersRequest
|
|
116
120
|
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { fetch } = require('wix-fetch');
|
|
2
|
-
const { items: wixData } = require('@wix/data');
|
|
3
1
|
const { executeApiRequest } = require('tests-utils');
|
|
4
2
|
const { getRandomPosition } = require('./testsUtils');
|
|
5
3
|
|
|
@@ -32,43 +30,23 @@ describe('Job details fetch from SR API Tests', () => {
|
|
|
32
30
|
expect(jobFetchResponse.data.result.applyUrl.length).toBeGreaterThan(0);
|
|
33
31
|
expect(jobFetchResponse.data.result.location).toBeDefined();
|
|
34
32
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
33
|
});
|
|
40
34
|
|
|
41
35
|
describe('fetchPositionsFromSRAPI error handling', () => {
|
|
42
|
-
|
|
36
|
+
test('should return 0 positions if invalid companyId is found', async () => {
|
|
37
|
+
const requestBody = `fetchPositionsFromSRAPI(invalid_company_id);`;
|
|
38
|
+
positions = await executeApiRequest(requestBody);
|
|
39
|
+
expect(positions.data.result.totalFound).toBe(0);
|
|
40
|
+
expect(positions.data.result.content.length).toBe(0);
|
|
41
|
+
});
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
test('throw error when bad request', async () => {
|
|
44
|
+
const requestBody = `makeSmartRecruitersRequest('/v1/error/companyId/postings');`;
|
|
45
|
+
response = await executeApiRequest(requestBody);
|
|
46
|
+
console.log(response);
|
|
47
|
+
expect(response.status).toBe(500);
|
|
47
48
|
|
|
48
|
-
jest.doMock('wix-fetch', () => ({
|
|
49
|
-
fetch: mockFetch,
|
|
50
|
-
}));
|
|
51
49
|
|
|
52
|
-
jest.doMock('@wix/data', () => ({
|
|
53
|
-
items: {
|
|
54
|
-
query: () => ({
|
|
55
|
-
limit: () => ({
|
|
56
|
-
find: () => Promise.resolve({ items: [{ companyId: 'company-123' }] }),
|
|
57
|
-
}),
|
|
58
|
-
}),
|
|
59
|
-
},
|
|
60
|
-
}));
|
|
61
|
-
});
|
|
62
50
|
|
|
63
|
-
test('throws on 400 Bad Request from SmartRecruiters', async () => {
|
|
64
|
-
mockFetch.mockResolvedValue({ ok: false, status: 400 });
|
|
65
|
-
const { fetchPositionsFromSRAPI } = require('../backend/fetchPositionsFromSRAPI');
|
|
66
|
-
await expect(fetchPositionsFromSRAPI()).rejects.toThrow('HTTP error! status: 400');
|
|
67
|
-
});
|
|
68
51
|
|
|
69
|
-
test('throws on network failure while fetching positions', async () => {
|
|
70
|
-
mockFetch.mockRejectedValue(new Error('Network failure'));
|
|
71
|
-
const { fetchPositionsFromSRAPI } = require('../backend/fetchPositionsFromSRAPI');
|
|
72
|
-
await expect(fetchPositionsFromSRAPI()).rejects.toThrow('Network failure');
|
|
73
|
-
});
|
|
74
52
|
});
|