Skip to content

Commit

Permalink
SLSCMN-3 config service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Nov 25, 2023
1 parent b344e5a commit 4ca7886
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default {
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: ['<rootDir>/jest.setup.ts'],
setupFiles: ['<rootDir>/jest.setup.ts'],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],
Expand Down
6 changes: 6 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// declare env vars
process.env.AWS_EXECUTION_ENV = 'aws-execution-env';
process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '128';
process.env.AWS_LAMBDA_FUNCTION_NAME = 'aws-lambda-function-name';
process.env.AWS_LAMBDA_FUNCTION_VERSION = 'aws-lambda-function-version';
process.env.AWS_REGION = 'aws-region';
20 changes: 20 additions & 0 deletions src/services/__tests__/config.service-failure.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ServiceError } from '../../errors/service.error';
import { LambdaConfig, lambdaConfigSchema, validateConfig } from '../config.service';

describe('ConfigService Failure', () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
delete process.env.AWS_REGION;
});

afterEach(() => {
process.env = originalEnv;
});

it('should throw error when validation fails', () => {
expect(() => validateConfig<LambdaConfig>(lambdaConfigSchema)).toThrow(ServiceError);
});
});
20 changes: 20 additions & 0 deletions src/services/__tests__/config.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LambdaConfig, lambdaConfigSchema, validateConfig } from '../config.service';

describe('ConfigService', () => {
it('should validate successfully', () => {
const validatedConfig = validateConfig<LambdaConfig>(lambdaConfigSchema);

expect(validatedConfig).toBeDefined();
});

it('should return LambdaConfig attributes', () => {
const validatedConfig = validateConfig<LambdaConfig>(lambdaConfigSchema);

expect(validatedConfig).toBeDefined();
expect(validatedConfig.AWS_EXECUTION_ENV).toBe('aws-execution-env');
expect(validatedConfig.AWS_LAMBDA_FUNCTION_MEMORY_SIZE).toBe('128');
expect(validatedConfig.AWS_LAMBDA_FUNCTION_NAME).toBe('aws-lambda-function-name');
expect(validatedConfig.AWS_LAMBDA_FUNCTION_VERSION).toBe('aws-lambda-function-version');
expect(validatedConfig.AWS_REGION).toBe('aws-region');
});
});

0 comments on commit 4ca7886

Please sign in to comment.