Skip to content

Commit 227650d

Browse files
authored
Merge pull request #22 from BitGo/WP-4695-add-mocha-integration-tests
feat: integration test setup and move to mocha
2 parents bf8f0d4 + a5cc8cf commit 227650d

File tree

11 files changed

+614
-92
lines changed

11 files changed

+614
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
coverage/
44
.idea/
55
logs/
6+
tsconfig.tsbuildinfo

.mocharc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
require: ['ts-node/register'],
3+
extension: ['ts'],
4+
timeout: 0,
5+
ui: 'bdd',
6+
spec: 'src/**/__tests__/**/*.test.ts',
7+
recursive: true,
8+
exit: true
9+
};

jest.config.js

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

package.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,42 @@
1010
"scripts": {
1111
"start": "nodemon bin/enclaved-bitgo-express",
1212
"build": "yarn tsc --build --incremental --verbose . && cp package.json dist/",
13-
"test": "jest",
14-
"test:watch": "jest --watch",
15-
"test:coverage": "jest --coverage",
13+
"test": "mocha --require ts-node/register 'src/**/__tests__/**/*.test.ts'",
14+
"test:watch": "mocha --require ts-node/register --watch 'src/**/__tests__/**/*.test.ts'",
15+
"test:coverage": "nyc mocha --require ts-node/register 'src/**/__tests__/**/*.test.ts'",
1616
"lint": "eslint --quiet .",
1717
"generate-test-ssl": "openssl req -x509 -newkey rsa:2048 -keyout test-ssl-key.pem -out test-ssl-cert.pem -days 365 -nodes -subj '/CN=localhost'"
1818
},
1919
"dependencies": {
2020
"@api-ts/io-ts-http": "^3.2.1",
21-
"@api-ts/response": "^2.1.0",
2221
"@api-ts/openapi-generator": "^5.7.0",
23-
"@api-ts/typed-express-router": "^1.1.13",
22+
"@api-ts/response": "^2.1.0",
23+
"@api-ts/typed-express-router": "^1.1.13",
2424
"@bitgo/sdk-core": "^35.2.0",
2525
"bitgo": "^48.0.0",
2626
"body-parser": "^1.20.3",
2727
"connect-timeout": "^1.9.0",
2828
"debug": "^3.1.0",
29-
"io-ts": "2.1.3",
30-
"winston": "^3.11.0",
3129
"express": "4.17.3",
30+
"io-ts": "2.1.3",
3231
"lodash": "^4.17.20",
3332
"morgan": "^1.9.1",
3433
"proxy-agent": "6.4.0",
3534
"proxyquire": "^2.1.3",
3635
"superagent": "^8.0.9",
36+
"winston": "^3.11.0",
3737
"zod": "^3.25.48"
3838
},
3939
"devDependencies": {
4040
"@api-ts/openapi-generator": "^5.7.0",
41-
"nodemon": "^3.1.10",
4241
"@types/body-parser": "^1.17.0",
4342
"@types/connect-timeout": "^1.9.0",
4443
"@types/debug": "^4.1.12",
4544
"@types/express": "4.17.13",
45+
"@types/jasmine": "^5.1.8",
4646
"@types/jest": "^29.5.12",
4747
"@types/lodash": "^4.14.121",
48+
"@types/mocha": "^10.0.10",
4849
"@types/morgan": "^1.7.35",
4950
"@types/node": "^16.18.46",
5051
"@types/sinon": "^10.0.11",
@@ -55,8 +56,11 @@
5556
"eslint": "^8.0.0",
5657
"eslint-config-prettier": "^8.0.0",
5758
"eslint-plugin-prettier": "^4.0.0",
59+
"jasmine": "^5.8.0",
5860
"jest": "^29.7.0",
61+
"mocha": "^11.6.0",
5962
"nock": "^13.3.1",
63+
"nodemon": "^3.1.10",
6064
"nyc": "^15.0.0",
6165
"prettier": "^2.0.0",
6266
"should": "^13.2.3",
@@ -65,7 +69,9 @@
6569
"sinon": "^13.0.1",
6670
"supertest": "^4.0.2",
6771
"ts-jest": "^29.1.2",
68-
"typescript": "^4.2.4"
72+
"ts-node": "^10.9.2",
73+
"typescript": "^4.2.4",
74+
"typescript-cached-transpile": "^0.0.6"
6975
},
7076
"engines": {
7177
"node": ">=22.1.0"

src/__tests__/config.test.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'should';
12
import { config, isEnclavedConfig, TlsMode } from '../config';
23

34
describe('Configuration', () => {
@@ -6,23 +7,26 @@ describe('Configuration', () => {
67
const mockTlsCert = '-----BEGIN CERTIFICATE-----\nMOCK_CERT\n-----END CERTIFICATE-----';
78

89
beforeEach(() => {
9-
jest.resetModules();
1010
process.env = { ...originalEnv };
1111
// Clear TLS-related environment variables
1212
delete process.env.TLS_MODE;
1313
});
1414

15-
afterAll(() => {
15+
after(() => {
1616
process.env = originalEnv;
1717
});
1818

1919
it('should throw error when APP_MODE is not set', () => {
20-
expect(() => config()).toThrow('APP_MODE environment variable is required');
20+
(() => config()).should.throw(
21+
'APP_MODE environment variable is required. Set APP_MODE to either "enclaved" or "master-express"',
22+
);
2123
});
2224

2325
it('should throw error when APP_MODE is invalid', () => {
2426
process.env.APP_MODE = 'invalid';
25-
expect(() => config()).toThrow('Invalid APP_MODE: invalid');
27+
(() => config()).should.throw(
28+
'Invalid APP_MODE: invalid. Must be either "enclaved" or "master-express"',
29+
);
2630
});
2731

2832
describe('Enclaved Mode', () => {
@@ -36,64 +40,66 @@ describe('Configuration', () => {
3640

3741
it('should use default configuration when no environment variables are set', () => {
3842
const cfg = config();
39-
expect(isEnclavedConfig(cfg)).toBe(true);
43+
isEnclavedConfig(cfg).should.be.true();
4044
if (isEnclavedConfig(cfg)) {
41-
expect(cfg.port).toBe(3080);
42-
expect(cfg.bind).toBe('localhost');
43-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
44-
expect(cfg.timeout).toBe(305 * 1000);
45-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
46-
expect(cfg.tlsKey).toBe(mockTlsKey);
47-
expect(cfg.tlsCert).toBe(mockTlsCert);
45+
cfg.port.should.equal(3080);
46+
cfg.bind.should.equal('localhost');
47+
cfg.tlsMode.should.equal(TlsMode.MTLS);
48+
cfg.timeout.should.equal(305 * 1000);
49+
cfg.kmsUrl.should.equal('http://localhost:3000');
50+
cfg.tlsKey!.should.equal(mockTlsKey);
51+
cfg.tlsCert!.should.equal(mockTlsCert);
4852
}
4953
});
5054

5155
it('should read port from environment variable', () => {
5256
process.env.ENCLAVED_EXPRESS_PORT = '4000';
5357
const cfg = config();
54-
expect(isEnclavedConfig(cfg)).toBe(true);
58+
isEnclavedConfig(cfg).should.be.true();
5559
if (isEnclavedConfig(cfg)) {
56-
expect(cfg.port).toBe(4000);
57-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
58-
expect(cfg.tlsKey).toBe(mockTlsKey);
59-
expect(cfg.tlsCert).toBe(mockTlsCert);
60+
cfg.port.should.equal(4000);
61+
cfg.kmsUrl.should.equal('http://localhost:3000');
62+
cfg.tlsKey!.should.equal(mockTlsKey);
63+
cfg.tlsCert!.should.equal(mockTlsCert);
6064
}
6165
});
6266

6367
it('should read TLS mode from environment variables', () => {
6468
// Test with TLS disabled
6569
process.env.TLS_MODE = 'disabled';
6670
let cfg = config();
67-
expect(isEnclavedConfig(cfg)).toBe(true);
71+
isEnclavedConfig(cfg).should.be.true();
6872
if (isEnclavedConfig(cfg)) {
69-
expect(cfg.tlsMode).toBe(TlsMode.DISABLED);
70-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
73+
cfg.tlsMode.should.equal(TlsMode.DISABLED);
74+
cfg.kmsUrl.should.equal('http://localhost:3000');
7175
}
7276

7377
// Test with mTLS explicitly enabled
7478
process.env.TLS_MODE = 'mtls';
7579
cfg = config();
76-
expect(isEnclavedConfig(cfg)).toBe(true);
80+
isEnclavedConfig(cfg).should.be.true();
7781
if (isEnclavedConfig(cfg)) {
78-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
79-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
80-
expect(cfg.tlsKey).toBe(mockTlsKey);
81-
expect(cfg.tlsCert).toBe(mockTlsCert);
82+
cfg.tlsMode.should.equal(TlsMode.MTLS);
83+
cfg.kmsUrl.should.equal('http://localhost:3000');
84+
cfg.tlsKey!.should.equal(mockTlsKey);
85+
cfg.tlsCert!.should.equal(mockTlsCert);
8286
}
8387

8488
// Test with invalid TLS mode
8589
process.env.TLS_MODE = 'invalid';
86-
expect(() => config()).toThrow('Invalid TLS_MODE: invalid');
90+
(() => config()).should.throw(
91+
'Invalid TLS_MODE: invalid. Must be either "disabled" or "mtls"',
92+
);
8793

8894
// Test with no TLS mode (should default to MTLS)
8995
delete process.env.TLS_MODE;
9096
cfg = config();
91-
expect(isEnclavedConfig(cfg)).toBe(true);
97+
isEnclavedConfig(cfg).should.be.true();
9298
if (isEnclavedConfig(cfg)) {
93-
expect(cfg.tlsMode).toBe(TlsMode.MTLS);
94-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
95-
expect(cfg.tlsKey).toBe(mockTlsKey);
96-
expect(cfg.tlsCert).toBe(mockTlsCert);
99+
cfg.tlsMode.should.equal(TlsMode.MTLS);
100+
cfg.kmsUrl.should.equal('http://localhost:3000');
101+
cfg.tlsKey!.should.equal(mockTlsKey);
102+
cfg.tlsCert!.should.equal(mockTlsCert);
97103
}
98104
});
99105

@@ -103,13 +109,13 @@ describe('Configuration', () => {
103109
process.env.MTLS_ALLOWED_CLIENT_FINGERPRINTS = 'ABC123,DEF456';
104110

105111
const cfg = config();
106-
expect(isEnclavedConfig(cfg)).toBe(true);
112+
isEnclavedConfig(cfg).should.be.true();
107113
if (isEnclavedConfig(cfg)) {
108-
expect(cfg.mtlsRequestCert).toBe(true);
109-
expect(cfg.mtlsAllowedClientFingerprints).toEqual(['ABC123', 'DEF456']);
110-
expect(cfg.kmsUrl).toBe('http://localhost:3000');
111-
expect(cfg.tlsKey).toBe(mockTlsKey);
112-
expect(cfg.tlsCert).toBe(mockTlsCert);
114+
cfg.mtlsRequestCert!.should.be.true();
115+
cfg.mtlsAllowedClientFingerprints!.should.deepEqual(['ABC123', 'DEF456']);
116+
cfg.kmsUrl.should.equal('http://localhost:3000');
117+
cfg.tlsKey!.should.equal(mockTlsKey);
118+
cfg.tlsCert!.should.equal(mockTlsCert);
113119
}
114120
});
115121
});

src/__tests__/index.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import 'should';
2+
13
describe('Basic test setup', () => {
24
it('should pass a basic test', () => {
3-
expect(true).toBe(true);
5+
true.should.be.true();
46
});
57

68
it('should handle basic math', () => {
7-
expect(1 + 1).toBe(2);
9+
(1 + 1).should.equal(2);
810
});
911
});

0 commit comments

Comments
 (0)