sr-npm 1.0.18 → 1.0.21
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/backend/data.js
CHANGED
|
@@ -336,8 +336,7 @@ async function clearCollections() {
|
|
|
336
336
|
await Promise.all([
|
|
337
337
|
wixData.truncate(COLLECTIONS.CITIES),
|
|
338
338
|
wixData.truncate(COLLECTIONS.AMOUNT_OF_JOBS_PER_DEPARTMENT),
|
|
339
|
-
wixData.truncate(COLLECTIONS.JOBS)
|
|
340
|
-
wixData.truncate(COLLECTIONS.SECRET_MANAGER_MIRROR)
|
|
339
|
+
wixData.truncate(COLLECTIONS.JOBS)
|
|
341
340
|
]);
|
|
342
341
|
console.log("cleared collections successfully");
|
|
343
342
|
}
|
|
@@ -375,11 +374,13 @@ async function fillSecretManagerMirror() {
|
|
|
375
374
|
});
|
|
376
375
|
console.log("x-smarttoken inserted into the SecretManagerMirror collection");
|
|
377
376
|
} catch (error) {
|
|
378
|
-
console.
|
|
377
|
+
console.warn("Error with inserting x-smarttoken into the SecretManagerMirror collection:", error);
|
|
379
378
|
}
|
|
380
379
|
}
|
|
381
380
|
|
|
382
381
|
|
|
382
|
+
|
|
383
|
+
|
|
383
384
|
module.exports = {
|
|
384
385
|
syncJobsFast,
|
|
385
386
|
referenceJobs,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
|
-
const {
|
|
3
|
-
const {
|
|
2
|
+
const { TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
3
|
+
const { getTokenFromCMS,getApiKeys } = require('./secretsData');
|
|
4
4
|
async function makeSmartRecruitersRequest(path,templateType) {
|
|
5
5
|
const baseUrl = 'https://api.smartrecruiters.com';
|
|
6
6
|
const fullUrl = `${baseUrl}${path}`;
|
|
@@ -103,38 +103,21 @@ async function fetchPositionsFromSRAPI(testObject=undefined) {
|
|
|
103
103
|
return result;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async function fetchJobDescription(jobId) {
|
|
107
|
-
|
|
106
|
+
async function fetchJobDescription(jobId,testObject=undefined) {
|
|
107
|
+
let companyId, templateType;
|
|
108
|
+
if (testObject) {
|
|
109
|
+
({ companyId, templateType } = testObject);
|
|
110
|
+
} else {
|
|
111
|
+
({ companyId, templateType } = await getApiKeys());
|
|
112
|
+
}
|
|
108
113
|
return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
|
|
112
|
-
async function getTokenFromCMS(tokenName) {
|
|
113
|
-
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName',tokenName).find();
|
|
114
|
-
if (result.items.length > 0) {
|
|
115
|
-
return result.items[0].tokenValue;
|
|
116
|
-
} else {
|
|
117
|
-
throw new Error(`[getTokenFromCMS], No ${tokenName} found`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
async function getTemplateTypeFromCMS() {
|
|
121
|
-
const result = await wixData.query(COLLECTIONS.TEMPLATE_TYPE).limit(1).find();
|
|
122
|
-
if (result.items.length > 0) {
|
|
123
|
-
return result.items[0].templateType;
|
|
124
|
-
} else {
|
|
125
|
-
throw new Error('[getTemplateTypeFromCMS], No templateType found');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
117
|
|
|
129
|
-
async function getApiKeys() {
|
|
130
|
-
const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
|
|
131
|
-
const templateType = await getTemplateTypeFromCMS();
|
|
132
|
-
return {companyId,templateType};
|
|
133
|
-
}
|
|
134
118
|
|
|
135
119
|
module.exports = {
|
|
136
120
|
fetchPositionsFromSRAPI,
|
|
137
121
|
fetchJobDescription,
|
|
138
|
-
getTokenFromCMS,
|
|
139
122
|
makeSmartRecruitersRequest
|
|
140
123
|
};
|
package/backend/secretsData.js
CHANGED
|
@@ -1,22 +1,57 @@
|
|
|
1
1
|
const { secrets } = require("@wix/secrets");
|
|
2
2
|
const { auth } = require('@wix/essentials');
|
|
3
|
+
const { items: wixData } = require('@wix/data');
|
|
4
|
+
const { COLLECTIONS,TOKEN_NAME } = require('./collectionConsts');
|
|
3
5
|
|
|
4
6
|
const getSecretValue = auth.elevate(secrets.getSecretValue);
|
|
5
7
|
|
|
6
8
|
function getSmartToken() {
|
|
7
|
-
return
|
|
9
|
+
return retrieveSecretVal(TOKEN_NAME.SMART_TOKEN)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getCompanyId() {
|
|
13
|
+
return retrieveSecretVal(TOKEN_NAME.COMPANY_ID_SM)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function retrieveSecretVal(tokenName)
|
|
17
|
+
{
|
|
18
|
+
return getSecretValue(tokenName)
|
|
8
19
|
.then((secret) => {
|
|
9
20
|
return secret;
|
|
21
|
+
}).catch(async (error) => {
|
|
22
|
+
console.warn("Error retrieving secret value: ", error)
|
|
23
|
+
console.warn("Retrying with getTokenFromCMS")
|
|
24
|
+
const secret = await getTokenFromCMS(tokenName);
|
|
25
|
+
return secret
|
|
10
26
|
})
|
|
11
|
-
}
|
|
27
|
+
}
|
|
12
28
|
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return
|
|
17
|
-
|
|
29
|
+
async function getTokenFromCMS(tokenName) {
|
|
30
|
+
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName',tokenName).find();
|
|
31
|
+
if (result.items.length > 0) {
|
|
32
|
+
return result.items[0].tokenValue;
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error(`[getTokenFromCMS], No ${tokenName} found`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function getTemplateTypeFromCMS() {
|
|
38
|
+
const result = await wixData.query(COLLECTIONS.TEMPLATE_TYPE).limit(1).find();
|
|
39
|
+
if (result.items.length > 0) {
|
|
40
|
+
return result.items[0].templateType;
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error('[getTemplateTypeFromCMS], No templateType found');
|
|
43
|
+
}
|
|
18
44
|
}
|
|
45
|
+
|
|
46
|
+
async function getApiKeys() {
|
|
47
|
+
const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
|
|
48
|
+
const templateType = await getTemplateTypeFromCMS();
|
|
49
|
+
return {companyId,templateType};
|
|
50
|
+
}
|
|
51
|
+
|
|
19
52
|
module.exports = {
|
|
20
53
|
getCompanyId,
|
|
21
|
-
getSmartToken
|
|
54
|
+
getSmartToken,
|
|
55
|
+
getTokenFromCMS,
|
|
56
|
+
getApiKeys
|
|
22
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sr-npm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@hisense-staging/velo-npm": "3.0.19",
|
|
21
21
|
"@wix/data": "^1.0.211",
|
|
22
22
|
"@wix/essentials": "^0.1.24",
|
|
23
|
-
"@wix/secrets": "
|
|
23
|
+
"@wix/secrets": "1.0.53",
|
|
24
24
|
"@wix/site-location": "^1.0.0",
|
|
25
25
|
"@wix/site-window": "^1.0.0",
|
|
26
26
|
"axios": "^1.11.0",
|
|
@@ -3,33 +3,43 @@ const { getRandomPosition, executeRequestAndTest } = require('./testsUtils');
|
|
|
3
3
|
|
|
4
4
|
describe('Job details fetch from SR API Tests', () => {
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
expect(randomPosition.location).toBeDefined();
|
|
20
|
-
expect(randomPosition.department).toBeDefined();
|
|
21
|
-
});
|
|
6
|
+
const templateTypes = [
|
|
7
|
+
{ templatename: 'External', templateType: 'PUBLIC'},
|
|
8
|
+
{ templatename: 'Internal', templateType: 'INTERNAL'}
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
templateTypes.forEach(({ templateType ,templatename}) => {
|
|
12
|
+
describe(`Job details fetch from SR API Tests - ${templatename}`, () => {
|
|
13
|
+
let positions;
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
const fetchPositionsFromSRAPIRequestBody = `fetchPositionsFromSRAPI({companyId:'WixTest',templateType: '${templateType}'});`;
|
|
16
|
+
positions = await executeApiRequest(fetchPositionsFromSRAPIRequestBody);
|
|
17
|
+
});
|
|
18
|
+
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
test(`should successfully fetch job details from SR API (${templatename})`, async () => {
|
|
21
|
+
const randomPosition = getRandomPosition(positions.data.result.content);
|
|
22
|
+
expect(positions.data.result.totalFound).toBeGreaterThan(0);
|
|
23
|
+
expect(positions.data.result.content.length).toBeGreaterThan(0);
|
|
24
|
+
expect(randomPosition.id.length).toBeGreaterThan(0);
|
|
25
|
+
expect(randomPosition.name.length).toBeGreaterThan(0);
|
|
26
|
+
expect(randomPosition.jobAdId.length).toBeGreaterThan(0);
|
|
27
|
+
expect(randomPosition.location).toBeDefined();
|
|
28
|
+
expect(randomPosition.department).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test(`should successfully fetch job description from SR API (${templatename})`, async () => {
|
|
32
|
+
const randomPosition = getRandomPosition(positions.data.result.content);
|
|
33
|
+
const fetchJobDescriptionRequestBody = `fetchJobDescription(${randomPosition.id},{companyId:'WixTest',templateType: '${templateType}'});`;
|
|
34
|
+
const jobFetchResponse = await executeApiRequest(fetchJobDescriptionRequestBody);
|
|
35
|
+
expect(jobFetchResponse.data.result.id).toBe(randomPosition.id);
|
|
36
|
+
expect(jobFetchResponse.data.result.jobAd.sections.jobDescription).toBeDefined();
|
|
37
|
+
expect(jobFetchResponse.data.result.jobAd.sections.jobDescription.text.length).toBeGreaterThan(0);
|
|
38
|
+
expect(jobFetchResponse.data.result.applyUrl.length).toBeGreaterThan(0);
|
|
39
|
+
expect(jobFetchResponse.data.result.location).toBeDefined();
|
|
40
|
+
});
|
|
32
41
|
});
|
|
42
|
+
});
|
|
33
43
|
});
|
|
34
44
|
|
|
35
45
|
describe('fetchPositionsFromSRAPI error handling', () => {
|