sr-npm 1.7.461 → 1.7.462
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/collectionConsts.js +12 -0
- package/backend/consts.js +2 -1
- package/backend/data.js +9 -10
- package/backend/fetchPositionsFromSRAPI.js +24 -23
- package/backend/index.js +1 -0
- package/backend/secretsData.js +7 -9
- package/package.json +2 -2
- package/tests/consts.js +12 -0
- package/tests/fetchPositionsFromSRApiTest.spec.js +68 -29
- package/tests/markTemplateTest.spec.js +25 -0
- package/tests/testsUtils.js +22 -1
|
@@ -71,6 +71,16 @@ const COLLECTIONS_FIELDS = {
|
|
|
71
71
|
],
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
+
const TEMPLATE_TYPE = {
|
|
75
|
+
INTERNAL: 'INTERNAL',
|
|
76
|
+
EXTERNAL: 'PUBLIC',
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const TOKEN_NAME = {
|
|
80
|
+
COMPANY_ID: 'companyId',
|
|
81
|
+
SMART_TOKEN: 'x-smarttoken',
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
|
|
75
85
|
module.exports = {
|
|
76
86
|
COLLECTIONS,
|
|
@@ -78,4 +88,6 @@ const COLLECTIONS_FIELDS = {
|
|
|
78
88
|
JOBS_COLLECTION_FIELDS,
|
|
79
89
|
AMOUNT_OF_JOBS_PER_DEPARTMENT_COLLECTION_FIELDS,
|
|
80
90
|
CITIES_COLLECTION_FIELDS,
|
|
91
|
+
TEMPLATE_TYPE,
|
|
92
|
+
TOKEN_NAME,
|
|
81
93
|
};
|
package/backend/consts.js
CHANGED
package/backend/data.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { items: wixData } = require('@wix/data');
|
|
2
2
|
const { fetchPositionsFromSRAPI, fetchJobDescription } = require('./fetchPositionsFromSRAPI');
|
|
3
3
|
const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend');
|
|
4
|
-
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
|
|
4
|
+
const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS,TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
5
5
|
const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
|
|
6
6
|
const { getAllPositions } = require('./queries');
|
|
7
7
|
const { getCompanyId, getSmartToken } = require('./secretsData');
|
|
@@ -317,9 +317,6 @@ async function referenceJobs() {
|
|
|
317
317
|
|
|
318
318
|
async function syncJobsFast() {
|
|
319
319
|
console.log("Syncing jobs fast");
|
|
320
|
-
//database
|
|
321
|
-
|
|
322
|
-
|
|
323
320
|
await createCollections();
|
|
324
321
|
await clearCollections();
|
|
325
322
|
await fillSecretManagerMirror();
|
|
@@ -347,16 +344,18 @@ async function clearCollections() {
|
|
|
347
344
|
|
|
348
345
|
async function markTemplateAsExternal() {
|
|
349
346
|
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
|
|
350
|
-
await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
351
|
-
templateType:
|
|
347
|
+
const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
348
|
+
templateType: TEMPLATE_TYPE.EXTERNAL
|
|
352
349
|
});
|
|
350
|
+
return tempalte;
|
|
353
351
|
}
|
|
354
352
|
|
|
355
353
|
async function markTemplateAsInternal() {
|
|
356
354
|
await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
|
|
357
|
-
await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
358
|
-
templateType:
|
|
355
|
+
const tempalte = await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
|
|
356
|
+
templateType: TEMPLATE_TYPE.INTERNAL
|
|
359
357
|
});
|
|
358
|
+
return tempalte;
|
|
360
359
|
}
|
|
361
360
|
|
|
362
361
|
async function fillSecretManagerMirror() {
|
|
@@ -364,14 +363,14 @@ async function fillSecretManagerMirror() {
|
|
|
364
363
|
const companyId = await getCompanyId();
|
|
365
364
|
console.log("companyId is : ", companyId);
|
|
366
365
|
await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
|
|
367
|
-
tokenName:
|
|
366
|
+
tokenName: TOKEN_NAME.COMPANY_ID,
|
|
368
367
|
tokenValue: companyId.value
|
|
369
368
|
});
|
|
370
369
|
console.log("companyId inserted into the SecretManagerMirror collection");
|
|
371
370
|
try{
|
|
372
371
|
const token = await getSmartToken();
|
|
373
372
|
await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
|
|
374
|
-
tokenName:
|
|
373
|
+
tokenName: TOKEN_NAME.SMART_TOKEN,
|
|
375
374
|
tokenValue: token.value
|
|
376
375
|
});
|
|
377
376
|
console.log("x-smarttoken inserted into the SecretManagerMirror collection");
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
const { fetch } = require('wix-fetch');
|
|
2
2
|
const { items: wixData } = require('@wix/data');
|
|
3
|
-
const { COLLECTIONS } = require('./collectionConsts');
|
|
4
|
-
|
|
3
|
+
const { COLLECTIONS,TEMPLATE_TYPE,TOKEN_NAME } = require('./collectionConsts');
|
|
5
4
|
async function makeSmartRecruitersRequest(path,templateType) {
|
|
6
5
|
const baseUrl = 'https://api.smartrecruiters.com';
|
|
7
6
|
const fullUrl = `${baseUrl}${path}`;
|
|
8
7
|
|
|
9
8
|
try {
|
|
10
|
-
//if templatetype is internal make headers object with x-smarttoken
|
|
11
9
|
const headers = {
|
|
12
10
|
'Accept-Language': 'en',
|
|
13
11
|
'accept': 'application/json',
|
|
14
12
|
'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
|
|
15
13
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const smartToken = await getSmartTokenFromCMS();
|
|
14
|
+
if (templateType === TEMPLATE_TYPE.INTERNAL) {
|
|
15
|
+
const smartToken = await getTokenFromCMS(TOKEN_NAME.SMART_TOKEN);
|
|
19
16
|
headers['x-smarttoken'] = smartToken;
|
|
20
17
|
}
|
|
21
18
|
const response = await fetch(fullUrl, {
|
|
@@ -35,12 +32,18 @@ async function makeSmartRecruitersRequest(path,templateType) {
|
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
async function fetchPositionsFromSRAPI() {
|
|
35
|
+
async function fetchPositionsFromSRAPI(testObject=undefined) {
|
|
39
36
|
let allPositions = [];
|
|
40
37
|
let totalFound = 0;
|
|
41
38
|
let page = 0;
|
|
42
39
|
const MAX_PAGES = 30 // Safety limit to prevent infinite loops
|
|
43
|
-
|
|
40
|
+
|
|
41
|
+
let companyId, templateType;
|
|
42
|
+
if (testObject) {
|
|
43
|
+
({ companyId, templateType } = testObject);
|
|
44
|
+
} else {
|
|
45
|
+
({ companyId, templateType } = await getApiKeys());
|
|
46
|
+
}
|
|
44
47
|
console.log('Starting to fetch all positions with pagination...');
|
|
45
48
|
let offset=0;
|
|
46
49
|
|
|
@@ -100,26 +103,23 @@ async function fetchPositionsFromSRAPI() {
|
|
|
100
103
|
return result;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
async function fetchJobDescription(jobId) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async function getCompanyIdFromCMS() {
|
|
109
|
-
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','companyId').find();
|
|
110
|
-
if (result.items.length > 0) {
|
|
111
|
-
return result.items[0].tokenValue;
|
|
106
|
+
async function fetchJobDescription(jobId,testObject=undefined) {
|
|
107
|
+
let companyId, templateType;
|
|
108
|
+
if (testObject) {
|
|
109
|
+
({ companyId, templateType } = testObject);
|
|
112
110
|
} else {
|
|
113
|
-
|
|
111
|
+
({ companyId, templateType } = await getApiKeys());
|
|
114
112
|
}
|
|
113
|
+
return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
|
|
117
|
+
async function getTokenFromCMS(tokenName) {
|
|
118
|
+
const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName',tokenName).find();
|
|
119
119
|
if (result.items.length > 0) {
|
|
120
120
|
return result.items[0].tokenValue;
|
|
121
121
|
} else {
|
|
122
|
-
throw new Error(
|
|
122
|
+
throw new Error(`[getTokenFromCMS], No ${tokenName} found`);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
async function getTemplateTypeFromCMS() {
|
|
@@ -132,7 +132,7 @@ async function getTemplateTypeFromCMS() {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
async function getApiKeys() {
|
|
135
|
-
const companyId = await
|
|
135
|
+
const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
|
|
136
136
|
const templateType = await getTemplateTypeFromCMS();
|
|
137
137
|
return {companyId,templateType};
|
|
138
138
|
}
|
|
@@ -140,5 +140,6 @@ async function getApiKeys() {
|
|
|
140
140
|
module.exports = {
|
|
141
141
|
fetchPositionsFromSRAPI,
|
|
142
142
|
fetchJobDescription,
|
|
143
|
-
|
|
143
|
+
getTokenFromCMS,
|
|
144
|
+
makeSmartRecruitersRequest
|
|
144
145
|
};
|
package/backend/index.js
CHANGED
package/backend/secretsData.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
const { secrets } = require("@wix/secrets");
|
|
2
2
|
const { auth } = require('@wix/essentials');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const getSecretValue = auth.elevate(secrets.getSecretValue);
|
|
5
5
|
|
|
6
6
|
function getSmartToken() {
|
|
7
|
-
return
|
|
7
|
+
return getSecretValue("x-smarttoken")
|
|
8
8
|
.then((secret) => {
|
|
9
9
|
return secret;
|
|
10
10
|
})
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
console.log("
|
|
15
|
-
|
|
16
|
-
console.log("
|
|
17
|
-
|
|
18
|
-
console.log("print_me is : ", print_me);
|
|
19
|
-
console.log("Getting the company ID$#%%$# from the ^$%$^^%secrets");
|
|
13
|
+
function getCompanyId() {
|
|
14
|
+
console.log("Getting the company ID from the secrets");
|
|
15
|
+
const getSecretValue2 = auth.elevate(secrets.getSecretValue);
|
|
16
|
+
console.log("getSecretValue2 is : ", getSecretValue2);
|
|
17
|
+
|
|
20
18
|
return getSecretValue2("companyID")
|
|
21
19
|
.then((secret) => {
|
|
22
20
|
return secret;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sr-npm",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.462",
|
|
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": "^1.0.
|
|
23
|
+
"@wix/secrets": "^1.0.56",
|
|
24
24
|
"@wix/site-location": "^1.0.0",
|
|
25
25
|
"@wix/site-window": "^1.0.0",
|
|
26
26
|
"axios": "^1.11.0",
|
package/tests/consts.js
ADDED
|
@@ -1,35 +1,74 @@
|
|
|
1
1
|
const { executeApiRequest } = require('tests-utils');
|
|
2
|
-
const { getRandomPosition } = require('./testsUtils');
|
|
2
|
+
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
|
-
|
|
20
|
-
|
|
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
|
+
|
|
19
|
+
|
|
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
|
+
});
|
|
22
30
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('fetchPositionsFromSRAPI error handling', () => {
|
|
46
|
+
test('should throw error if invalid companyId is found external template', async () => {
|
|
47
|
+
const requestBody = `fetchPositionsFromSRAPI({companyId: 'invalid_company_id',templateType: 'EXTERNAL'});`;
|
|
48
|
+
executeRequestAndTest(requestBody)
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should throw error if invalid companyId is found internal template', async () => {
|
|
52
|
+
const requestBody = `fetchPositionsFromSRAPI({companyId: 'invalid_company_id',templateType: 'INTERNAL'});`;
|
|
53
|
+
executeRequestAndTest(requestBody)
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should throw error when a bad URL is used', async () => {
|
|
57
|
+
const requestBody = `makeSmartRecruitersRequest('/v1/error/companyId/postings');`;
|
|
58
|
+
executeRequestAndTest(requestBody)
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('fetchJobDescription error handling', () => {
|
|
66
|
+
test('should throw error if invalid jobId is given', async () => {
|
|
67
|
+
const requestBody = `fetchJobDescription('invalid_job_id');`;
|
|
68
|
+
executeRequestAndTest(requestBody)
|
|
69
|
+
});
|
|
70
|
+
test('should throw error when given a valid but wrong jobId is given', async () => {
|
|
71
|
+
const requestBody = `fetchJobDescription('1234567890');`;
|
|
72
|
+
executeRequestAndTest(requestBody)
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { executeApiRequest } = require('tests-utils');
|
|
2
|
+
const { clearCollections } = require('./testsUtils');
|
|
3
|
+
const { TEMPLATE_TYPE } = require('./consts');
|
|
4
|
+
|
|
5
|
+
beforeAll(async () => {
|
|
6
|
+
clearCollections();
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
it.each([
|
|
12
|
+
{ templateName: 'Internal', templateType: TEMPLATE_TYPE.INTERNAL },
|
|
13
|
+
{ templateName: 'External', templateType: TEMPLATE_TYPE.EXTERNAL },
|
|
14
|
+
])('should successfully mark template as $templateName', async ({ templateName,templateType }) => {
|
|
15
|
+
const requestBody = `markTemplateAs${templateName}();`;
|
|
16
|
+
const response = await executeApiRequest(requestBody);
|
|
17
|
+
expect(response.status).toBe(200);
|
|
18
|
+
expect(response.data).toBeDefined();
|
|
19
|
+
expect(response.data.result.templateType).toBe(templateType);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
package/tests/testsUtils.js
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
+
const { executeApiRequest } = require('tests-utils');
|
|
2
|
+
const { COLLECTIONS } = require('./consts');
|
|
3
|
+
const { items: wixData } = require('@wix/data');
|
|
4
|
+
|
|
1
5
|
function getRandomPosition(positions) {
|
|
2
6
|
return positions[Math.floor(Math.random() * positions.length)];
|
|
3
7
|
}
|
|
8
|
+
async function executeRequestAndTest(requestBody) {
|
|
9
|
+
try{
|
|
10
|
+
response = await executeApiRequest(requestBody);
|
|
11
|
+
expect(response.status).not.toBe(500);
|
|
12
|
+
}catch(error){
|
|
13
|
+
expect(error.message).toBe('Request failed with status code 500');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function clearCollections() {
|
|
18
|
+
|
|
19
|
+
for (const collection of Object.values(COLLECTIONS)) {
|
|
20
|
+
await wixData.truncate(collection);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
4
23
|
|
|
5
24
|
module.exports = {
|
|
6
|
-
getRandomPosition
|
|
25
|
+
getRandomPosition,
|
|
26
|
+
executeRequestAndTest,
|
|
27
|
+
clearCollections
|
|
7
28
|
}
|