Skip to content

Commit c212c90

Browse files
feat: added more tests
1 parent 4dff002 commit c212c90

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/idempotency/tests/helpers/populateEnvironmentVariables.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ const populateEnvironmentVariables = (): void => {
22
process.env.AWS_LAMBDA_FUNCTION_NAME = 'hello-world';
33

44
};
5+
6+
const deleteEnvironmentVariables = (): void => {
7+
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
8+
}
59

610
export {
11+
deleteEnvironmentVariables,
712
populateEnvironmentVariables,
813
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Test Tracer class
3+
*
4+
* @group unit/idempotency/all
5+
*/
6+
import { EnvironmentVariablesService } from '../../src/EnvironmentVariablesService';
7+
8+
describe('Class: EnvironmentVariableService', ()=> {
9+
describe('Method: getLambdaFunctionName', ()=> {
10+
beforeEach(() => {
11+
process.env.AWS_LAMBDA_FUNCTION_NAME = 'testFunction';
12+
});
13+
14+
afterEach(()=> {
15+
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
16+
});
17+
18+
test('When called it getse the Lambda function name from the environment variable', ()=> {
19+
const expectedName = process.env.AWS_LAMBDA_FUNCTION_NAME;
20+
21+
const lambdaName = new EnvironmentVariablesService().getLambdaFunctionName();
22+
23+
expect(lambdaName).toEqual(expectedName);
24+
});
25+
26+
test('When called without the environment variable set it returns an empty string', ()=> {
27+
delete process.env.AWS_LAMBDA_FUNCTION_NAME;
28+
29+
const lambdaName = new EnvironmentVariablesService().getLambdaFunctionName();
30+
31+
expect(lambdaName).toEqual('');
32+
});
33+
});
34+
});

packages/idempotency/tests/unit/PersistenceLayer.test.ts renamed to packages/idempotency/tests/unit/persistence/PersistenceLayer.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* @group unit/idempotency/all
55
*/
66
import { createHash, Hash } from 'crypto';
7-
import { EnvironmentVariablesService } from '../../src/EnvironmentVariablesService';
8-
import { IdempotencyRecord, PersistenceLayer } from '../../src/persistence';
9-
import { IdempotencyRecordStatus } from '../../src/types/IdempotencyRecordStatus';
7+
import { EnvironmentVariablesService } from '../../../src/EnvironmentVariablesService';
8+
import { IdempotencyRecord, PersistenceLayer } from '../../../src/persistence';
9+
import { IdempotencyRecordStatus } from '../../../src/types/IdempotencyRecordStatus';
1010

1111
jest.mock('crypto', () => ({
1212
createHash: jest.fn(),

0 commit comments

Comments
 (0)