sr-npm 1.7.418 → 1.7.420

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/consts.js CHANGED
@@ -73,6 +73,15 @@ const TASKS = {
73
73
  }
74
74
 
75
75
 
76
+ const TEMPLATE_TYPE = {
77
+ INTERNAL: 'INTERNAL',
78
+ EXTERNAL: 'PUBLIC',
79
+ }
80
+
81
+ const TOKEN_NAME = {
82
+ COMPANY_ID: 'companyId',
83
+ SMART_TOKEN: 'x-smarttoken',
84
+ }
76
85
 
77
86
  const TASK_TYPE = {
78
87
  SCHEDULED: 'scheduled',
@@ -83,5 +92,7 @@ const TASK_TYPE = {
83
92
  TASKS_NAMES,
84
93
  TASK_TYPE,
85
94
  TASKS,
86
- QUERY_MAX_LIMIT
95
+ QUERY_MAX_LIMIT,
96
+ TEMPLATE_TYPE,
97
+ TOKEN_NAME
87
98
  };
package/backend/data.js CHANGED
@@ -4,6 +4,7 @@ const { createCollectionIfMissing } = require('@hisense-staging/velo-npm/backend
4
4
  const { COLLECTIONS, COLLECTIONS_FIELDS,JOBS_COLLECTION_FIELDS } = require('./collectionConsts');
5
5
  const { chunkedBulkOperation, countJobsPerGivenField, fillCityLocationAndLocationAddress ,prepareToSaveArray,normalizeCityName} = require('./utils');
6
6
  const { getAllPositions } = require('./queries');
7
+ const{TEMPLATE_TYPE,TOKEN_NAME} = require('./consts');
7
8
  const { getCompanyId, getSmartToken } = require('./secretsData');
8
9
 
9
10
  function validatePosition(position) {
@@ -317,9 +318,6 @@ async function referenceJobs() {
317
318
 
318
319
  async function syncJobsFast() {
319
320
  console.log("Syncing jobs fast");
320
- //database
321
-
322
-
323
321
  await createCollections();
324
322
  await clearCollections();
325
323
  await fillSecretManagerMirror();
@@ -348,14 +346,14 @@ async function clearCollections() {
348
346
  async function markTemplateAsExternal() {
349
347
  await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
350
348
  await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
351
- templateType: "PUBLIC"
349
+ templateType: TEMPLATE_TYPE.EXTERNAL
352
350
  });
353
351
  }
354
352
 
355
353
  async function markTemplateAsInternal() {
356
354
  await createCollectionIfMissing(COLLECTIONS.TEMPLATE_TYPE, COLLECTIONS_FIELDS.TEMPLATE_TYPE,null,'singleItem');
357
355
  await wixData.save(COLLECTIONS.TEMPLATE_TYPE, {
358
- templateType: "INTERNAL"
356
+ templateType: TEMPLATE_TYPE.INTERNAL
359
357
  });
360
358
  }
361
359
 
@@ -364,14 +362,14 @@ async function fillSecretManagerMirror() {
364
362
  const companyId = await getCompanyId();
365
363
  console.log("companyId is : ", companyId);
366
364
  await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
367
- tokenName: "companyId",
365
+ tokenName: TOKEN_NAME.COMPANY_ID,
368
366
  tokenValue: companyId.value
369
367
  });
370
368
  console.log("companyId inserted into the SecretManagerMirror collection");
371
369
  try{
372
370
  const token = await getSmartToken();
373
371
  await wixData.insert(COLLECTIONS.SECRET_MANAGER_MIRROR, {
374
- tokenName: "x-smarttoken",
372
+ tokenName: TOKEN_NAME.SMART_TOKEN,
375
373
  tokenValue: token.value
376
374
  });
377
375
  console.log("x-smarttoken inserted into the SecretManagerMirror collection");
@@ -1,21 +1,20 @@
1
1
  const { fetch } = require('wix-fetch');
2
2
  const { items: wixData } = require('@wix/data');
3
3
  const { COLLECTIONS } = require('./collectionConsts');
4
+ const { TEMPLATE_TYPE,TOKEN_NAME } = require('./consts');
4
5
 
5
6
  async function makeSmartRecruitersRequest(path,templateType) {
6
7
  const baseUrl = 'https://api.smartrecruiters.com';
7
8
  const fullUrl = `${baseUrl}${path}`;
8
9
 
9
10
  try {
10
- //if templatetype is internal make headers object with x-smarttoken
11
11
  const headers = {
12
12
  'Accept-Language': 'en',
13
13
  'accept': 'application/json',
14
14
  'Cookie': 'AWSALB=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d; AWSALBCORS=GYltFw3fLKortMxHR5vIOT1CuUROyhWNIX/qL8ZnPl1/8mhOcnIsBKYslzmNJPEzSy/jvNbO+6tXpH8yqcpQJagYt57MhbKlLqTSzoNq1G/w7TjOxPGR3UTdXW0d'
15
15
  };
16
- //here is the only place where we check templateType
17
- if (templateType === 'INTERNAL') {
18
- const smartToken = await getSmartTokenFromCMS();
16
+ if (templateType === TEMPLATE_TYPE.INTERNAL) {
17
+ const smartToken = await getTokenFromCMS(TOKEN_NAME.SMART_TOKEN);
19
18
  headers['x-smarttoken'] = smartToken;
20
19
  }
21
20
  const response = await fetch(fullUrl, {
@@ -35,7 +34,7 @@ async function makeSmartRecruitersRequest(path,templateType) {
35
34
  }
36
35
  }
37
36
 
38
- async function fetchPositionsFromSRAPI() {
37
+ async function fetchPositionsFromSRAPI(companyID=undefined) {
39
38
  let allPositions = [];
40
39
  let totalFound = 0;
41
40
  let page = 0;
@@ -105,21 +104,13 @@ async function fetchJobDescription(jobId) {
105
104
  return await makeSmartRecruitersRequest(`/v1/companies/${companyId}/postings/${jobId}`,templateType);
106
105
  }
107
106
 
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;
112
- } else {
113
- throw new Error('[getCompanyIdFromCMS], No companyId found');
114
- }
115
- }
116
107
 
117
- async function getSmartTokenFromCMS() {
118
- const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName','x-smarttoken').find();
108
+ async function getTokenFromCMS(tokenName) {
109
+ const result = await wixData.query(COLLECTIONS.SECRET_MANAGER_MIRROR).eq('tokenName',tokenName).find();
119
110
  if (result.items.length > 0) {
120
111
  return result.items[0].tokenValue;
121
112
  } else {
122
- throw new Error('[getSmartTokenFromCMS], No smarttoken found');
113
+ throw new Error(`[getTokenFromCMS], No ${tokenName} found`);
123
114
  }
124
115
  }
125
116
  async function getTemplateTypeFromCMS() {
@@ -132,7 +123,7 @@ async function getTemplateTypeFromCMS() {
132
123
  }
133
124
 
134
125
  async function getApiKeys() {
135
- const companyId = await getCompanyIdFromCMS();
126
+ const companyId = await getTokenFromCMS(TOKEN_NAME.COMPANY_ID);
136
127
  const templateType = await getTemplateTypeFromCMS();
137
128
  return {companyId,templateType};
138
129
  }
@@ -140,5 +131,5 @@ async function getApiKeys() {
140
131
  module.exports = {
141
132
  fetchPositionsFromSRAPI,
142
133
  fetchJobDescription,
143
- getCompanyIdFromCMS
134
+ getTokenFromCMS
144
135
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sr-npm",
3
- "version": "1.7.418",
3
+ "version": "1.7.420",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,7 @@
1
+ const COLLECTIONS = {
2
+ TEMPLATE_TYPE: 'templateType',
3
+ }
4
+
5
+ module.exports = {
6
+ COLLECTIONS
7
+ }
@@ -1,35 +1,59 @@
1
- const { executeApiRequest } = require('tests-utils');
2
- const { getRandomPosition } = require('./testsUtils');
1
+ // const { executeApiRequest } = require('tests-utils');
2
+ // const { getRandomPosition, executeRequestAndTest } = require('./testsUtils');
3
3
 
4
- describe('Job details fetch from SR API Tests', () => {
4
+ // describe('Job details fetch from SR API Tests', () => {
5
5
 
6
- let positions;
7
- beforeAll(async () => {
8
- const requestBody = `fetchPositionsFromSRAPI();`;
9
- positions = await executeApiRequest(requestBody);
10
- });
6
+ // let positions;
7
+ // beforeAll(async () => {
8
+ // const requestBody = `fetchPositionsFromSRAPI();`;
9
+ // positions = await executeApiRequest(requestBody);
10
+ // });
11
11
 
12
- test('should successfully fetch job details from SR API', async () => {
13
- const randomPosition = getRandomPosition(positions.data.result.content);
14
- expect(positions.data.result.totalFound).toBeGreaterThan(0);
15
- expect(positions.data.result.content.length).toBeGreaterThan(0);
16
- expect(randomPosition.id.length).toBeGreaterThan(0);
17
- expect(randomPosition.name.length).toBeGreaterThan(0);
18
- expect(randomPosition.jobAdId.length).toBeGreaterThan(0);
19
- expect(randomPosition.location).toBeDefined();
20
- expect(randomPosition.department).toBeDefined();
21
- });
22
-
23
- test('should successfully fetch job description from SR API', async () => {
24
- const randomPosition = getRandomPosition(positions.data.result.content);
25
- const fetchJobDescriptionRequestBody = `fetchJobDescription(${randomPosition.id});`;
26
- const jobFetchResponse = await executeApiRequest(fetchJobDescriptionRequestBody);
27
- expect(jobFetchResponse.data.result.id).toBe(randomPosition.id);
28
- expect(jobFetchResponse.data.result.jobAd.sections.jobDescription).toBeDefined();
29
- expect(jobFetchResponse.data.result.jobAd.sections.jobDescription.text.length).toBeGreaterThan(0);
30
- expect(jobFetchResponse.data.result.applyUrl.length).toBeGreaterThan(0);
31
- expect(jobFetchResponse.data.result.location).toBeDefined();
32
- });
33
-
34
-
35
- });
12
+ // test('should successfully fetch job details from SR API', async () => {
13
+ // const randomPosition = getRandomPosition(positions.data.result.content);
14
+ // expect(positions.data.result.totalFound).toBeGreaterThan(0);
15
+ // expect(positions.data.result.content.length).toBeGreaterThan(0);
16
+ // expect(randomPosition.id.length).toBeGreaterThan(0);
17
+ // expect(randomPosition.name.length).toBeGreaterThan(0);
18
+ // expect(randomPosition.jobAdId.length).toBeGreaterThan(0);
19
+ // expect(randomPosition.location).toBeDefined();
20
+ // expect(randomPosition.department).toBeDefined();
21
+ // });
22
+
23
+ // test('should successfully fetch job description from SR API', async () => {
24
+ // const randomPosition = getRandomPosition(positions.data.result.content);
25
+ // const fetchJobDescriptionRequestBody = `fetchJobDescription(${randomPosition.id});`;
26
+ // const jobFetchResponse = await executeApiRequest(fetchJobDescriptionRequestBody);
27
+ // expect(jobFetchResponse.data.result.id).toBe(randomPosition.id);
28
+ // expect(jobFetchResponse.data.result.jobAd.sections.jobDescription).toBeDefined();
29
+ // expect(jobFetchResponse.data.result.jobAd.sections.jobDescription.text.length).toBeGreaterThan(0);
30
+ // expect(jobFetchResponse.data.result.applyUrl.length).toBeGreaterThan(0);
31
+ // expect(jobFetchResponse.data.result.location).toBeDefined();
32
+ // });
33
+ // });
34
+
35
+ // describe('fetchPositionsFromSRAPI error handling', () => {
36
+ // test('should throw error if invalid companyId is found', async () => {
37
+ // const requestBody = `fetchPositionsFromSRAPI('invalid_company_id');`;
38
+ // executeRequestAndTest(requestBody)
39
+ // });
40
+
41
+ // test('should throw error when a bad URL is used', async () => {
42
+ // const requestBody = `makeSmartRecruitersRequest('/v1/error/companyId/postings');`;
43
+ // executeRequestAndTest(requestBody)
44
+ // });
45
+
46
+
47
+
48
+ // });
49
+
50
+ // describe('fetchJobDescription error handling', () => {
51
+ // test('should throw error if invalid jobId is given', async () => {
52
+ // const requestBody = `fetchJobDescription('invalid_job_id');`;
53
+ // executeRequestAndTest(requestBody)
54
+ // });
55
+ // test('should throw error when given a valid but wrong jobId is given', async () => {
56
+ // const requestBody = `fetchJobDescription('1234567890');`;
57
+ // executeRequestAndTest(requestBody)
58
+ // });
59
+ // });
@@ -0,0 +1,27 @@
1
+ const { executeApiRequest } = require('tests-utils');
2
+ const { items: wixData } = require('@wix/data');
3
+ const { clearCollections } = require('./testsUtils');
4
+ const { TEMPLATE_TYPE } = require('../backend/consts');
5
+ const { COLLECTIONS } = require('./consts');
6
+
7
+ beforeAll(async () => {
8
+ clearCollections(wixData);
9
+ });
10
+
11
+
12
+
13
+
14
+ it.each([
15
+ { name: 'internal', templateType: TEMPLATE_TYPE.INTERNAL },
16
+ { name: 'external', templateType: TEMPLATE_TYPE.EXTERNAL },
17
+ ])('should successfully mark template as $name', async ({ templateType }) => {
18
+ const requestBody = `markTemplateAs${templateType}();`;
19
+ await executeApiRequest(requestBody);
20
+ const templateType = await wixData.query(COLLECTIONS.TEMPLATE_TYPE).limit(1).find();
21
+ expect(templateType.items[0].templateType).toBe(templateType);
22
+ });
23
+
24
+
25
+
26
+
27
+
@@ -1,7 +1,27 @@
1
+ const { executeApiRequest } = require('tests-utils');
2
+ const { COLLECTIONS } = require('./consts');
3
+
1
4
  function getRandomPosition(positions) {
2
5
  return positions[Math.floor(Math.random() * positions.length)];
3
6
  }
7
+ async function executeRequestAndTest(requestBody) {
8
+ try{
9
+ response = await executeApiRequest(requestBody);
10
+ expect(response.status).not.toBe(500);
11
+ }catch(error){
12
+ expect(error.message).toBe('Request failed with status code 500');
13
+ }
14
+ }
15
+
16
+ async function clearCollections(wixData) {
17
+
18
+ for (const collection of Object.values(COLLECTIONS)) {
19
+ await wixData.truncate(collection);
20
+ }
21
+ }
4
22
 
5
23
  module.exports = {
6
- getRandomPosition
24
+ getRandomPosition,
25
+ executeRequestAndTest,
26
+ clearCollections
7
27
  }