UNPKG

@gp_jcisneros/aws-utils

Version:

AWS SDK utilities for GreenPay microservices

84 lines (74 loc) 3.5 kB
const awsUtils = require('../src/index'); describe('AWS Utils Index', () => { it('should export all utility classes', () => { expect(awsUtils.LambdaUtils).toBeDefined(); expect(awsUtils.S3Utils).toBeDefined(); expect(awsUtils.SQSUtils).toBeDefined(); expect(awsUtils.DynamoUtils).toBeDefined(); }); it('should export error classes', () => { expect(awsUtils.AWSError).toBeDefined(); expect(awsUtils.DatabaseError).toBeDefined(); expect(awsUtils.IntegrationError).toBeDefined(); }); it('should export convenience functions', () => { expect(awsUtils.invokeLambda).toBeDefined(); expect(awsUtils.uploadToS3).toBeDefined(); expect(awsUtils.sendToSQS).toBeDefined(); expect(awsUtils.getFromDynamo).toBeDefined(); }); it('should have correct function types', () => { expect(typeof awsUtils.invokeLambda).toBe('function'); expect(typeof awsUtils.uploadToS3).toBe('function'); expect(typeof awsUtils.sendToSQS).toBe('function'); expect(typeof awsUtils.getFromDynamo).toBe('function'); }); it('should have correct class types', () => { expect(typeof awsUtils.LambdaUtils).toBe('function'); expect(typeof awsUtils.S3Utils).toBe('function'); expect(typeof awsUtils.SQSUtils).toBe('function'); expect(typeof awsUtils.DynamoUtils).toBe('function'); }); it('should have correct error class types', () => { expect(typeof awsUtils.AWSError).toBe('function'); expect(typeof awsUtils.DatabaseError).toBe('function'); expect(typeof awsUtils.IntegrationError).toBe('function'); }); describe('error classes', () => { it('should create AWSError with new constructor', () => { const error = new awsUtils.AWSError('Test error', 'S3', 'UPLOAD_ERROR'); expect(error).toBeInstanceOf(awsUtils.AWSError); expect(error.message).toBe('Test error'); expect(error.service).toBe('S3'); expect(error.awsErrorCode).toBe('UPLOAD_ERROR'); expect(error.statusCode).toBe(500); }); it('should create DatabaseError with new constructor', () => { const error = new awsUtils.DatabaseError('Test error', 'GET', 'users'); expect(error).toBeInstanceOf(awsUtils.DatabaseError); expect(error.message).toBe('Test error'); expect(error.operation).toBe('GET'); expect(error.table).toBe('users'); expect(error.statusCode).toBe(500); }); it('should create IntegrationError with new constructor', () => { const error = new awsUtils.IntegrationError('Test error', 'SERVICE_ERROR', 'external-service', { key: 'value' }); expect(error).toBeInstanceOf(awsUtils.IntegrationError); expect(error.message).toBe('Test error'); expect(error.integrationCode).toBe('SERVICE_ERROR'); expect(error.integrationName).toBe('external-service'); expect(error.context).toEqual({ key: 'value' }); expect(error.statusCode).toBe(502); }); }); describe('convenience functions', () => { it('should be callable functions', () => { // Test that convenience functions exist and are callable // We'll just check that they are functions without calling them expect(typeof awsUtils.invokeLambda).toBe('function'); expect(typeof awsUtils.uploadToS3).toBe('function'); expect(typeof awsUtils.sendToSQS).toBe('function'); expect(typeof awsUtils.getFromDynamo).toBe('function'); }); }); });