Skip to content

Commit abff485

Browse files
S PadmaS Padma
authored andcommitted
check ts code
1 parent eb00726 commit abff485

10 files changed

Lines changed: 131 additions & 498 deletions

File tree

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@
1010
* - CI/CD: OAuth S2S with IMS_CLIENT_ID and IMS_CLIENT_SECRET
1111
* - Local: Adobe I/O CLI (aio auth login --bare)
1212
*
13-
* Run with: npm run test:query
13+
* Run with: npm run test:e2e
1414
*/
1515

16-
import dotenv from 'dotenv';
17-
import { fileURLToPath } from 'url';
18-
import { dirname, join } from 'path';
19-
import {
20-
describe, test, expect, beforeAll,
21-
} from '@jest/globals';
22-
import { ImsHelper } from '../utils/imsHelper.js';
23-
import makeQuery from '../utils/queryHelper.js';
16+
import * as dotenv from 'dotenv';
17+
import * as path from 'path';
18+
import { ImsHelper } from '../utils/imsHelper';
19+
import makeQuery from '../utils/queryHelper';
2420

2521
// Load environment variables
26-
const __filename = fileURLToPath(import.meta.url);
27-
const __dirname = dirname(__filename);
28-
dotenv.config({ path: join(__dirname, '..', '.env') });
22+
dotenv.config({ path: path.join(__dirname, '..', '.env') });
2923

3024
// IMS Token - fetched dynamically via OAuth (CI/CD) or aio CLI (local)
3125
// NOT stored in .env file for security reasons
@@ -37,7 +31,7 @@ describe('Query Endpoint E2E Tests', () => {
3731
try {
3832
VALID_IMS_TOKEN = await imsHelper.getToken();
3933
console.log('Valid IMS token obtained for testing');
40-
} catch (error) {
34+
} catch (error: any) {
4135
console.error('Failed to fetch IMS token:', error.message);
4236
}
4337
}, 30000); // 30 second timeout for token fetch
@@ -192,14 +186,14 @@ describe('Query Endpoint E2E Tests', () => {
192186

193187
// Should return results, but with low relevance scores
194188
if (data.results.length > 0) {
195-
const avgScore = data.results.reduce((sum, r) => sum + r.score, 0) / data.results.length;
189+
const avgScore = data.results.reduce((sum: number, r: any) => sum + r.score, 0) / data.results.length;
196190

197191
// Log for visibility
198192
console.log(`Invalid context query - avg score: ${avgScore.toFixed(4)}`);
199193
console.log(`Results returned: ${data.results.length}`);
200194

201195
// Results should have lower relevance scores (typically < 0.5 for unrelated content)
202-
data.results.forEach((result, idx) => {
196+
data.results.forEach((result: any, idx: number) => {
203197
console.log(`Result ${idx + 1} score: ${result.score.toFixed(4)}`);
204198
});
205199
} else {
@@ -227,3 +221,4 @@ describe('Query Endpoint E2E Tests', () => {
227221
});
228222
});
229223
});
224+

jest.config.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
5+
// Match test files
6+
testMatch: [
7+
'<rootDir>/e2e/**/*.test.ts',
8+
'<rootDir>/security-test/**/*.test.ts'
9+
],
10+
11+
// Setup file for polyfills
12+
setupFilesAfterEnv: ['<rootDir>/jest.setup.cjs'],
13+
14+
// Verbose output
15+
verbose: true,
16+
17+
// Ignore load tests (they use k6, not Jest)
18+
testPathIgnorePatterns: ['/node_modules/', '/load-test/']
19+
};

jest.config.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

jest.setup.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Jest Setup File
3+
* Initializes global objects needed for Azure SDK and fetch
4+
*/
5+
6+
const { webcrypto } = require('crypto');
7+
8+
// Make crypto available globally for Azure SDK
9+
global.crypto = webcrypto;
10+
11+
// Polyfill fetch for Node 18+ (in case Jest environment doesn't have it)
12+
if (typeof global.fetch === 'undefined') {
13+
global.fetch = require('node-fetch');
14+
global.Headers = require('node-fetch').Headers;
15+
global.Request = require('node-fetch').Request;
16+
global.Response = require('node-fetch').Response;
17+
}

jest.setup.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8-
"test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest e2e/ --verbose",
8+
"test": "jest --runInBand",
9+
"test:e2e": "jest e2e/ --verbose --runInBand",
10+
"test:e2e:watch": "jest e2e/ --watch",
911
"test:load": "export IMS_TOKEN=${IMS_TOKEN:-$(aio auth login --bare)} && mkdir -p load-test/results && for file in load-test/*.test.js; do [ -f \"$file\" ] && k6 run -e APIM_ENDPOINT=\"${APIM_ENDPOINT}\" -e IMS_TOKEN=\"${IMS_TOKEN}\" --out json=load-test/results/$(basename \"$file\" .test.js).json \"$file\"; done",
10-
"test:security": "NODE_OPTIONS=--experimental-vm-modules jest security-test/ --verbose --runInBand",
12+
"test:security": "jest security-test/ --verbose --runInBand",
1113
"lint": "echo 'No linter configured yet' && exit 0"
1214
},
1315
"keywords": [
@@ -35,8 +37,12 @@
3537
"@azure/data-tables": "^13.2.2",
3638
"@azure/functions": "^4.0.0",
3739
"@jest/globals": "^29.7.0",
40+
"@types/jest": "^29.2.2",
41+
"@types/node": "^18.19.0",
3842
"jest": "^29.7.0",
39-
"node-fetch": "^3.3.2"
43+
"node-fetch": "^3.3.2",
44+
"ts-jest": "^29.0.3",
45+
"typescript": "^4.8.4"
4046
},
4147
"engines": {
4248
"node": ">=18.0.0"

0 commit comments

Comments
 (0)