add test for check function
This commit is contained in:
parent
0ad7be85d4
commit
b7709c07ed
4 changed files with 3930 additions and 27 deletions
8
jest.config.js
Normal file
8
jest.config.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export default {
|
||||
preset: 'ts-jest/presets/default-esm',
|
||||
extensionsToTreatAsEsm: ['.ts'],
|
||||
testEnvironment: 'node',
|
||||
moduleNameMapper: {
|
||||
'^(\\.{1,2}/.*)\\.js$': '$1',
|
||||
},
|
||||
};
|
||||
3806
package-lock.json
generated
3806
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -3,9 +3,14 @@
|
|||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "tsx src/runner.ts"
|
||||
"start": "tsx src/runner.ts",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/globals": "^29.7.0",
|
||||
"@types/jest": "^29.5.8",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"tsx": "^4.7.0",
|
||||
"typescript": "^5.3.0"
|
||||
}
|
||||
|
|
|
|||
84
src/checks.test.ts
Normal file
84
src/checks.test.ts
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
import { createClientInitializationCheck } from './checks';
|
||||
|
||||
describe('createClientInitializationCheck', () => {
|
||||
it('should return SUCCESS for a valid initialize request', () => {
|
||||
const validRequest = {
|
||||
protocolVersion: '2025-06-18',
|
||||
clientInfo: {
|
||||
name: 'TestClient',
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(validRequest);
|
||||
expect(check.status).toBe('SUCCESS');
|
||||
expect(check.errorMessage).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return FAILURE when protocol version is missing', () => {
|
||||
const invalidRequest = {
|
||||
clientInfo: {
|
||||
name: 'TestClient',
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(invalidRequest);
|
||||
expect(check.status).toBe('FAILURE');
|
||||
expect(check.errorMessage).toContain('Protocol version not provided');
|
||||
});
|
||||
|
||||
it('should return FAILURE when protocol version does not match', () => {
|
||||
const invalidRequest = {
|
||||
protocolVersion: '2024-11-05',
|
||||
clientInfo: {
|
||||
name: 'TestClient',
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(invalidRequest);
|
||||
expect(check.status).toBe('FAILURE');
|
||||
expect(check.errorMessage).toContain('Version mismatch');
|
||||
});
|
||||
|
||||
it('should return FAILURE when client name is missing', () => {
|
||||
const invalidRequest = {
|
||||
protocolVersion: '2025-06-18',
|
||||
clientInfo: {
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(invalidRequest);
|
||||
expect(check.status).toBe('FAILURE');
|
||||
expect(check.errorMessage).toContain('Client name missing');
|
||||
});
|
||||
|
||||
it('should return FAILURE when client version is missing', () => {
|
||||
const invalidRequest = {
|
||||
protocolVersion: '2025-06-18',
|
||||
clientInfo: {
|
||||
name: 'TestClient'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(invalidRequest);
|
||||
expect(check.status).toBe('FAILURE');
|
||||
expect(check.errorMessage).toContain('Client version missing');
|
||||
});
|
||||
|
||||
it('should support custom expected spec version', () => {
|
||||
const request = {
|
||||
protocolVersion: '2024-11-05',
|
||||
clientInfo: {
|
||||
name: 'TestClient',
|
||||
version: '1.0.0'
|
||||
}
|
||||
};
|
||||
|
||||
const check = createClientInitializationCheck(request, '2024-11-05');
|
||||
expect(check.status).toBe('SUCCESS');
|
||||
expect(check.errorMessage).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue