From 0f465446fc2c9045f2e4eaf8e0c88a205e1b0bb5 Mon Sep 17 00:00:00 2001 From: Koichi Murakami Date: Mon, 2 Dec 2024 22:40:40 +0900 Subject: [PATCH] Add detailed instructions and single quotes in tests Expanded the README.md for the sequence package with detailed installation and setup instructions. Enhanced code readability in the sequence service test file by replacing double quotes with single quotes, which is the project's preferred style. Alongside this, the installation command description was standardized across various README.md files. --- packages/cli/README.md | 2 +- packages/core/README.md | 2 +- packages/sequence/README.md | 97 ++ packages/sequence/src/dto/gen-sequence.dto.ts | 3 +- .../sequence/src/sequences.service.spec.ts | 1025 +++++++++-------- packages/sequence/src/sequences.service.ts | 5 +- 6 files changed, 635 insertions(+), 499 deletions(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index bc6f2cc..4182c56 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -8,7 +8,7 @@ The MBC CLI is a command-line interface tool that helps you to initialize your m ## Installation -To install `mbc`, run: +To install `mbc` command, run: ```bash npm install -g @mbc-cqrs-serverless/cli diff --git a/packages/core/README.md b/packages/core/README.md index 098371f..e462d35 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -8,7 +8,7 @@ This is the core package of the MBC CQRS Serverless framework. It provides the b ## Installation -To install `mbc`, run: +To install `mbc` command, run: ```bash npm install -g @mbc-cqrs-serverless/cli diff --git a/packages/sequence/README.md b/packages/sequence/README.md index 627d13f..09bcf52 100644 --- a/packages/sequence/README.md +++ b/packages/sequence/README.md @@ -2,6 +2,103 @@ # MBC CQRS serverless framework Sequence package +## Description + +This package is a sequence package that runs on the MBC CQRS serverless framework. +Used when assigning numbers. +Numbers can also be rotated by fiscal year, year, month, or day. + +## Installation mbc command to create a project + +To install `mbc` command, run: + +```bash +npm install -g @mbc-cqrs-serverless/cli +``` + +## Create a project + +### `mbc new|n [projectName@version]` + +There are 3 usages for the new command: + +- `mbc new` + - Creates a new project in the current folder using a default name with the latest framework version. +- `mbc new [projectName]` + - Creates a new project in the `projectName` folder using the latest framework version. +- `mbc new [projectName@version]` + - If the specified version exists, the CLI uses that exact version. + - If the provided version is a prefix, the CLI uses the latest version matching that prefix. + - If no matching version is found, the CLI logs an error and provides a list of available versions for the user. + +To change current directory + +```bash +cd [projectName] +``` + +## Installation + +```bash +npm i @mbc-cqrs-serverless/sequence +``` + +## Run the Development Server +1. Run npm run build to the build project using development mode. +2. Open in other terminal session and run npm run offline:docker +3. Open in other terminal session and run npm run migrate to migrate RDS and dynamoDB table +4. Finally, run npm run offline:sls to start serverless offline mode. + +After the server runs successfully, you can see: + +```bash +DEBUG[serverless-offline-sns][adapter]: successfully subscribed queue "http://localhost:9324/101010101010/notification-queue" to topic: "arn:aws:sns:ap-northeast-1:101010101010:MySnsTopic" +Offline Lambda Server listening on http://localhost:4000 +serverless-offline-aws-eventbridge :: Plugin ready +serverless-offline-aws-eventbridge :: Mock server running at port: 4010 +Starting Offline SQS at stage dev (ap-northeast-1) +Starting Offline Dynamodb Streams at stage dev (ap-northeast-1) + +Starting Offline at stage dev (ap-northeast-1) + +Offline [http for lambda] listening on http://localhost:3002 +Function names exposed for local invocation by aws-sdk: + * main: serverless-example-dev-main +Configuring JWT Authorization: ANY /{proxy+} + + ┌────────────────────────────────────────────────────────────────────────┐ + │ │ + │ ANY | http://localhost:3000/api/public │ + │ POST | http://localhost:3000/2015-03-31/functions/main/invocations │ + │ ANY | http://localhost:3000/swagger-ui/{proxy*} │ + │ POST | http://localhost:3000/2015-03-31/functions/main/invocations │ + │ ANY | http://localhost:3000/{proxy*} │ + │ POST | http://localhost:3000/2015-03-31/functions/main/invocations │ + │ │ + └────────────────────────────────────────────────────────────────────────┘ + +Server ready: http://localhost:3000 🚀 +``` + +You can also use several endpoints: + +- API gateway: http://localhost:3000 +- Offline Lambda Server: http://localhost:4000 +- HTTP for lambda: http://localhost:3002 +- Step functions: http://localhost:8083 +- DynamoDB: http://localhost:8000 +- DynamoDB admin: http://localhost:8001 +- SNS: http://localhost:4002 +- SQS: http://localhost:9324 +- SQS admin: http://localhost:9325 +- Localstack: http://localhost:4566 +- AppSync: http://localhost:4001 +- Cognito: http://localhost:9229 +- EventBridge: http://localhost:4010 +- Simple Email Service: http://localhost:8005 +- Run `npx prisma studio` to open studio web: http://localhost:5000 + + ## Documentation Visit https://mbc-cqrs-serverless.mbc-net.com/ to view the full documentation. diff --git a/packages/sequence/src/dto/gen-sequence.dto.ts b/packages/sequence/src/dto/gen-sequence.dto.ts index 50508f5..50e5bd8 100644 --- a/packages/sequence/src/dto/gen-sequence.dto.ts +++ b/packages/sequence/src/dto/gen-sequence.dto.ts @@ -109,5 +109,6 @@ export class GenerateFormattedSequenceDto { description: 'Parameters for generating the sequence. code1, code2,code3, code4, code5', }) - params: SequenceParamsDto + @IsOptional() + params?: SequenceParamsDto } diff --git a/packages/sequence/src/sequences.service.spec.ts b/packages/sequence/src/sequences.service.spec.ts index a1bcb6d..c3952d1 100644 --- a/packages/sequence/src/sequences.service.spec.ts +++ b/packages/sequence/src/sequences.service.spec.ts @@ -1,11 +1,11 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { SequencesService } from './sequences.service'; -import { DynamoDbService, JwtClaims } from '@mbc-cqrs-serverless/core'; -import { Logger } from '@nestjs/common'; -import { RotateByEnum } from './enums/rotate-by.enum'; -import { FiscalYearOptions } from './interfaces/fiscal-year.interface'; -import { SequenceMasterDataProvider } from './sequence-master-factory'; -import { SequenceEntity } from './entities/sequence.entity'; +import { Test, TestingModule } from '@nestjs/testing' +import { SequencesService } from './sequences.service' +import { DynamoDbService, JwtClaims, toISOStringWithTimezone } from '@mbc-cqrs-serverless/core' +import { Logger } from '@nestjs/common' +import { RotateByEnum } from './enums/rotate-by.enum' +import { FiscalYearOptions } from './interfaces/fiscal-year.interface' +import { SequenceMasterDataProvider } from './sequence-master-factory' +import { SequenceEntity } from './entities/sequence.entity' const optionsMock = { @@ -23,25 +23,25 @@ const optionsMock = { authorizer: { jwt: { claims: { - "custom:tenant": 'MBC', - "custom:roles": '[{"tenant":"MBC","role":"admin"}]', - } as JwtClaims - } - } - } + 'custom:tenant': 'MBC', + 'custom:roles': '[{"tenant":"MBC","role":"admin"}]', + } as JwtClaims, + }, + }, + }, }, context: { awsRequestId: '81bf1821-34b0-4dc5-a2ce-685d37d22f8c', - } + }, }, } describe('SequencesService', () => { - let service: SequencesService; - let dynamoDbService: DynamoDbService; - let masterService: SequenceMasterDataProvider; - const mockTableName = 'mockTableName'; - const tenantCode = 'MBC'; + let service: SequencesService + let dynamoDbService: DynamoDbService + let masterService: SequenceMasterDataProvider + const mockTableName = 'mockTableName' + const tenantCode = 'MBC' beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ @@ -63,56 +63,55 @@ describe('SequencesService', () => { }, Logger, ], - }).compile(); + }).compile() - service = module.get(SequencesService); - dynamoDbService = module.get(DynamoDbService); - masterService = module.get(SequenceMasterDataProvider); - }); + service = module.get(SequencesService) + dynamoDbService = module.get(DynamoDbService) + masterService = module.get(SequenceMasterDataProvider) + }) it('should be defined', () => { - expect(service).toBeDefined(); - }); + expect(service).toBeDefined() + }) it('should get table name on initialization', () => { - expect(dynamoDbService.getTableName).toHaveBeenCalledWith('sequences'); - expect(service['tableName']).toBe(mockTableName); - }); - + expect(dynamoDbService.getTableName).toHaveBeenCalledWith('sequences') + expect(service['tableName']).toBe(mockTableName) + }) describe('getCurrentSequence', () => { it('should call getItem with correct parameters and return the result', async () => { - const mockKey = { pk: "SEQ#MBC", sk: "TODO#TASK1#2024" }; + const mockKey = { pk: 'SEQ#MBC', sk: 'TODO#TASK1#2024' } const mockResponse = { - code: "TODO#TASK1#2024", - updatedBy: "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - createdIp: "127.0.0.1", + code: 'TODO#TASK1#2024', + updatedBy: '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + createdIp: '127.0.0.1', tenantCode: tenantCode, - type: "TODO", - createdAt: "2024-11-08T13:50:26+07:00", - updatedIp: "127.0.0.1", - createdBy: "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - requestId: "81bf1821-34b0-4dc5-a2ce-685d37d22f8c", - name: "fiscal_yearly", - sk: "TODO#TASK1#2024", + type: 'TODO', + createdAt: '2024-11-08T13:50:26+07:00', + updatedIp: '127.0.0.1', + createdBy: '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + requestId: '81bf1821-34b0-4dc5-a2ce-685d37d22f8c', + name: 'fiscal_yearly', + sk: 'TODO#TASK1#2024', attributes: { fiscal_year: 71, - issued_at: "2024-11-08T13:50:26+07:00", - formatted_no: "00TASK1-71-code3001", - no: 1 + issued_at: '2024-11-08T13:50:26+07:00', + formatted_no: '00TASK1-71-code3001', + no: 1, }, - pk: "SEQ#MBC", + pk: 'SEQ#MBC', seq: 1, - updatedAt: "2024-11-08T13:50:26+07:00" - }; - jest.spyOn(dynamoDbService, 'getItem').mockResolvedValue(mockResponse); + updatedAt: '2024-11-08T13:50:26+07:00', + } + jest.spyOn(dynamoDbService, 'getItem').mockResolvedValue(mockResponse) - const result = await service.getCurrentSequence(mockKey); - expect(dynamoDbService.getItem).toHaveBeenCalledWith(mockTableName, mockKey); - expect(result).toEqual(mockResponse); - }); - }); + const result = await service.getCurrentSequence(mockKey) + expect(dynamoDbService.getItem).toHaveBeenCalledWith(mockTableName, mockKey) + expect(result).toEqual(mockResponse) + }) + }) // Case 1: Default start month (April) and reference year 1953 // describe('getFiscalYear', () => { @@ -303,28 +302,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:44:15+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "7724a67e-ded6-4ebb-9c88-c14070e24012", - "name": "none", - "sk": "sequence#TODO#none", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T13:44:16+07:00" + 'code': 'sequence#TODO#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:44:15+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '7724a67e-ded6-4ebb-9c88-c14070e24012', + 'name': 'none', + 'sk': 'sequence#TODO#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:44:16+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#none", + id: 'SEQ#MBC#sequence#TODO#none', no: 1, - formattedNo: "1", - issuedAt: (new Date("2024-11-27T13:44:16+07:00")), + formattedNo: '1', + issuedAt: (new Date('2024-11-27T13:44:16+07:00')), }) const result = await service.generateSequenceItem( { @@ -333,12 +332,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:44:16+07:00"), + date: new Date('2024-11-27T13:44:16+07:00'), rotateBy: RotateByEnum.NONE, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with none rotation at second time', async () => { const mockMasterData = { @@ -346,42 +345,42 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:44:15+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "7724a67e-ded6-4ebb-9c88-c14070e24012", - "name": "none", - "sk": "sequence#TODO#none", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T13:44:16+07:00" + 'code': 'sequence#TODO#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:44:15+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '7724a67e-ded6-4ebb-9c88-c14070e24012', + 'name': 'none', + 'sk': 'sequence#TODO#none', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T13:44:16+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#none", + id: 'SEQ#MBC#sequence#TODO#none', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-11-27T13:44:16+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-11-27T13:44:16+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, typeCode: 'sequence', - date: new Date("2024-11-27T13:44:16+07:00"), + date: new Date('2024-11-27T13:44:16+07:00'), params: { code1: 'TODO', }, rotateBy: RotateByEnum.NONE, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with fiscal yearly rotation', async () => { const mockMasterData = { @@ -389,28 +388,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "fiscal_yearly", - "sk": "sequence#TODO#2024", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T13:54:04+07:00" + 'code': 'sequence#TODO#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'fiscal_yearly', + 'sk': 'sequence#TODO#2024', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2024", + id: 'SEQ#MBC#sequence#TODO#2024', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-11-27T13:54:04+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-11-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { @@ -419,12 +418,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:54:04+07:00"), + date: new Date('2024-11-27T13:54:04+07:00'), rotateBy: RotateByEnum.FISCAL_YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with fiscal yearly rotation, argument is a fiscal year that is the same as the previous fiscal year', async () => { @@ -433,28 +432,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "fiscal_yearly", - "sk": "sequence#TODO#2024", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T13:54:04+07:00" + 'code': 'sequence#TODO#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'fiscal_yearly', + 'sk': 'sequence#TODO#2024', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2024", + id: 'SEQ#MBC#sequence#TODO#2024', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-11-27T13:54:04+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-11-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { @@ -463,12 +462,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:54:04+07:00"), + date: new Date('2024-11-27T13:54:04+07:00'), rotateBy: RotateByEnum.FISCAL_YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with fiscal yearly rotation, argument is a fiscal year other than the previous fiscal year', async () => { @@ -477,28 +476,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-03-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "fiscal_yearly", - "sk": "sequence#TODO#2024", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-03-27T13:54:04+07:00" + 'code': 'sequence#TODO#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-03-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'fiscal_yearly', + 'sk': 'sequence#TODO#2024', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-03-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2024", + id: 'SEQ#MBC#sequence#TODO#2024', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-03-27T13:54:04+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-03-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { @@ -507,12 +506,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-03-27T13:54:04+07:00"), + date: new Date('2024-03-27T13:54:04+07:00'), rotateBy: RotateByEnum.FISCAL_YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with yearly rotation', async () => { @@ -521,28 +520,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "yearly", - "sk": "sequence#TODO#2024", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T13:54:04+07:00" + 'code': 'sequence#TODO#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'yearly', + 'sk': 'sequence#TODO#2024', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2024", + id: 'SEQ#MBC#sequence#TODO#2024', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-11-27T13:54:04+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-11-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { @@ -551,12 +550,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:54:04+07:00"), + date: new Date('2024-11-27T13:54:04+07:00'), rotateBy: RotateByEnum.YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with yearly rotation, argument is a year that is the same as the previous year', async () => { @@ -565,42 +564,42 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "yearly", - "sk": "sequence#TODO#2024", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T13:54:04+07:00" + 'code': 'sequence#TODO#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'yearly', + 'sk': 'sequence#TODO#2024', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2024", + id: 'SEQ#MBC#sequence#TODO#2024', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-11-27T13:54:04+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-11-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, typeCode: 'sequence', - date: new Date("2024-11-27T13:54:04+07:00"), + date: new Date('2024-11-27T13:54:04+07:00'), params: { code1: 'TODO', }, rotateBy: RotateByEnum.YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with yearly rotation, argument is a year other than the previous year', async () => { @@ -609,28 +608,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#2025", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2025-03-27T13:54:04+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "f4c867f7-0b25-439e-896a-d1df1537d589", - "name": "yearly", - "sk": "sequence#TODO#2025", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2025-03-27T13:54:04+07:00" + 'code': 'sequence#TODO#2025', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2025-03-27T13:54:04+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'f4c867f7-0b25-439e-896a-d1df1537d589', + 'name': 'yearly', + 'sk': 'sequence#TODO#2025', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2025-03-27T13:54:04+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#2025", + id: 'SEQ#MBC#sequence#TODO#2025', no: 1, - formattedNo: "1", - issuedAt: new Date("2025-03-27T13:54:04+07:00"), + formattedNo: '1', + issuedAt: new Date('2025-03-27T13:54:04+07:00'), }) const result = await service.generateSequenceItem( { @@ -639,12 +638,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2025-03-27T13:54:04+07:00"), + date: new Date('2025-03-27T13:54:04+07:00'), rotateBy: RotateByEnum.YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with monthly rotation', async () => { @@ -653,42 +652,42 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#202411", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "monthly", - "sk": "sequence#TODO#202411", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T13:56:39+07:00" + 'code': 'sequence#TODO#202411', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'monthly', + 'sk': 'sequence#TODO#202411', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#202411", + id: 'SEQ#MBC#sequence#TODO#202411', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-11-27T13:56:39+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-11-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, typeCode: 'sequence', - date: new Date("2024-11-27T13:56:39+07:00"), + date: new Date('2024-11-27T13:56:39+07:00'), params: { code1: 'TODO', }, rotateBy: RotateByEnum.MONTHLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with monthly rotation, argument is a month other than the previous month', async () => { @@ -697,28 +696,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#202411", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "monthly", - "sk": "sequence#TODO#202411", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T13:56:39+07:00" + 'code': 'sequence#TODO#202411', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'monthly', + 'sk': 'sequence#TODO#202411', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#202411", + id: 'SEQ#MBC#sequence#TODO#202411', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-11-27T13:56:39+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-11-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { @@ -727,12 +726,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:56:39+07:00"), + date: new Date('2024-11-27T13:56:39+07:00'), rotateBy: RotateByEnum.MONTHLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with monthly rotation, argument is a month that is the same as the previous month', async () => { @@ -741,28 +740,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#202412", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-12-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "monthly", - "sk": "sequence#TODO#202412", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-12-27T13:56:39+07:00" + 'code': 'sequence#TODO#202412', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-12-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'monthly', + 'sk': 'sequence#TODO#202412', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-12-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#202412", + id: 'SEQ#MBC#sequence#TODO#202412', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-12-27T13:56:39+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-12-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { @@ -771,12 +770,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-12-27T13:56:39+07:00"), + date: new Date('2024-12-27T13:56:39+07:00'), rotateBy: RotateByEnum.MONTHLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with daily rotation ', async () => { @@ -785,28 +784,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#20241127", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "daily", - "sk": "sequence#TODO#20241127", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T13:56:39+07:00" + 'code': 'sequence#TODO#20241127', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'daily', + 'sk': 'sequence#TODO#20241127', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#20241127", + id: 'SEQ#MBC#sequence#TODO#20241127', no: 1, - formattedNo: "1", - issuedAt: new Date("2024-11-27T13:56:39+07:00"), + formattedNo: '1', + issuedAt: new Date('2024-11-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { @@ -815,12 +814,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-27T13:56:39+07:00"), + date: new Date('2024-11-27T13:56:39+07:00'), rotateBy: RotateByEnum.DAILY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with daily rotation, argument is a day other than the previous day', async () => { const mockMasterData = { @@ -828,42 +827,42 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#20241127", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "daily", - "sk": "sequence#TODO#20241127", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T13:56:39+07:00" + 'code': 'sequence#TODO#20241127', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'daily', + 'sk': 'sequence#TODO#20241127', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#20241127", + id: 'SEQ#MBC#sequence#TODO#20241127', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-11-27T13:56:39+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-11-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, - date: new Date("2024-11-27T13:56:39+07:00"), + date: new Date('2024-11-27T13:56:39+07:00'), typeCode: 'sequence', params: { code1: 'TODO', }, rotateBy: RotateByEnum.DAILY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with daily rotation, the argument is a day that is the same as the previous day', async () => { const mockMasterData = { @@ -871,28 +870,28 @@ describe('SequencesService', () => { format: '%%no%%', } const mockUpdate = { - "code": "sequence#TODO#20241227", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-12-27T13:56:39+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "bd482504-6076-46a3-8503-48063f4debd8", - "name": "daily", - "sk": "sequence#TODO#20241227", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-12-27T13:56:39+07:00" + 'code': 'sequence#TODO#20241227', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-12-27T13:56:39+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': 'bd482504-6076-46a3-8503-48063f4debd8', + 'name': 'daily', + 'sk': 'sequence#TODO#20241227', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-12-27T13:56:39+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#20241227", + id: 'SEQ#MBC#sequence#TODO#20241227', no: 2, - formattedNo: "2", - issuedAt: new Date("2024-12-27T13:56:39+07:00"), + formattedNo: '2', + issuedAt: new Date('2024-12-27T13:56:39+07:00'), }) const result = await service.generateSequenceItem( { @@ -901,12 +900,12 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-12-27T13:56:39+07:00"), + date: new Date('2024-12-27T13:56:39+07:00'), rotateBy: RotateByEnum.DAILY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with none rotation, the arguments have code 1, code 2, code 3, code4, code5 ', async () => { @@ -915,35 +914,35 @@ describe('SequencesService', () => { format: '%%code1%%-%%code2%%-%%code3%%-%%code4%%-%%code5%%-%%no%%', } const mockUpdate = { - "code": "sequence#TODO#ID2#ID3#ID4#ID5#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T14:36:18+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "0ff67305-18b6-4a9e-9226-b4f56fec6592", - "name": "none", - "sk": "sequence#TODO#ID2#ID3#ID4#ID5#none", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T14:36:18+07:00" + 'code': 'sequence#TODO#ID2#ID3#ID4#ID5#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T14:36:18+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '0ff67305-18b6-4a9e-9226-b4f56fec6592', + 'name': 'none', + 'sk': 'sequence#TODO#ID2#ID3#ID4#ID5#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T14:36:18+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#ID2#ID3#ID4#ID5#none", + id: 'SEQ#MBC#sequence#TODO#ID2#ID3#ID4#ID5#none', no: 1, - formattedNo: "TODO-ID2-ID3-ID4-ID5-1", - issuedAt: new Date("2024-11-27T13:44:16+07:00"), + formattedNo: 'TODO-ID2-ID3-ID4-ID5-1', + issuedAt: new Date('2024-11-27T13:44:16+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, typeCode: 'sequence', rotateBy: RotateByEnum.NONE, - date: new Date("2024-11-27T13:44:16+07:00"), + date: new Date('2024-11-27T13:44:16+07:00'), params: { code1: 'TODO', code2: 'ID2', @@ -952,9 +951,9 @@ describe('SequencesService', () => { code5: 'ID5', }, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with none rotation, format is %%code1%%-%%fiscal_year%%-%%no%%', async () => { const mockMasterData = { @@ -962,34 +961,34 @@ describe('SequencesService', () => { format: '%%code1%%-%%fiscal_year%%-%%no%%', } const mockUpdate = { - "code": "sequence#TODO#ID2#ID3#ID4#ID5#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T14:36:18+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "0ff67305-18b6-4a9e-9226-b4f56fec6592", - "name": "none", - "sk": "sequence#TODO#ID2#ID3#ID4#ID5#none", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-27T14:36:18+07:00" + 'code': 'sequence#TODO#ID2#ID3#ID4#ID5#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T14:36:18+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '0ff67305-18b6-4a9e-9226-b4f56fec6592', + 'name': 'none', + 'sk': 'sequence#TODO#ID2#ID3#ID4#ID5#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T14:36:18+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#ID2#ID3#ID4#ID5#none", + id: 'SEQ#MBC#sequence#TODO#ID2#ID3#ID4#ID5#none', no: 1, - formattedNo: "TODO-72-1", - issuedAt: new Date("2024-11-27T13:44:16+07:00"), + formattedNo: 'TODO-72-1', + issuedAt: new Date('2024-11-27T13:44:16+07:00'), }) const result = await service.generateSequenceItem( { tenantCode: tenantCode, typeCode: 'sequence', - date: new Date("2024-11-27T13:44:16+07:00"), + date: new Date('2024-11-27T13:44:16+07:00'), rotateBy: RotateByEnum.NONE, params: { code1: 'TODO', @@ -999,9 +998,9 @@ describe('SequencesService', () => { code5: 'ID5', }, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with none rotation, format is %%code1%%-%%month%%-%%no%%', async () => { const mockMasterData = { @@ -1009,29 +1008,29 @@ describe('SequencesService', () => { format: '%%code1%%-%%month%%-%%no%%', } const mockUpdate = { - "code": "sequence#TODO#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-06-13T13:44:16+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "0ff67305-18b6-4a9e-9226-b4f56fec6592", - "name": "none", - "sk": "sequence#TODO#none", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-06-13T13:44:16+07:00" + 'code': 'sequence#TODO#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-06-13T13:44:16+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '0ff67305-18b6-4a9e-9226-b4f56fec6592', + 'name': 'none', + 'sk': 'sequence#TODO#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-06-13T13:44:16+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#none", + id: 'SEQ#MBC#sequence#TODO#none', no: 1, - formattedNo: "TODO-6-1", - issuedAt: new Date("2024-06-13T13:44:16+07:00"), + formattedNo: 'TODO-6-1', + issuedAt: new Date('2024-06-13T13:44:16+07:00'), }) const result = await service.generateSequenceItem( { @@ -1041,11 +1040,11 @@ describe('SequencesService', () => { code1: 'TODO', }, rotateBy: RotateByEnum.YEARLY, - date: new Date("2024-06-13T13:44:16+07:00"), + date: new Date('2024-06-13T13:44:16+07:00'), }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with none rotation, format is %%code1%%-%%day%%-%%no%%', async () => { const mockMasterData = { @@ -1053,28 +1052,28 @@ describe('SequencesService', () => { format: '%%code1%%-%%day%%-%%no%%', } const mockUpdate = { - "code": "sequence#TODO#none", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-15T14:36:18+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "0ff67305-18b6-4a9e-9226-b4f56fec6592", - "name": "none", - "sk": "sequence#TODO#none", - "pk": "SEQ#MBC", - "seq": 1, - "updatedAt": "2024-11-15T14:36:18+07:00" + 'code': 'sequence#TODO#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-15T14:36:18+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '0ff67305-18b6-4a9e-9226-b4f56fec6592', + 'name': 'none', + 'sk': 'sequence#TODO#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-15T14:36:18+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#TODO#none", + id: 'SEQ#MBC#sequence#TODO#none', no: 1, - formattedNo: "TODO-15-1", - issuedAt: new Date("2024-11-15T13:44:16+07:00"), + formattedNo: 'TODO-15-1', + issuedAt: new Date('2024-11-15T13:44:16+07:00'), }) const result = await service.generateSequenceItem( { @@ -1083,42 +1082,42 @@ describe('SequencesService', () => { params: { code1: 'TODO', }, - date: new Date("2024-11-15T13:44:16+07:00"), + date: new Date('2024-11-15T13:44:16+07:00'), rotateBy: RotateByEnum.YEARLY, }, - optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) }) it('should call generateSequenceItem with register date, format is %%code1%%-%%fiscal_year%%-%%no%%', async () => { const mockMasterData = { typeCode: 'sequence', format: '%%code1%%-%%fiscal_year%%-%%no%%', - registerDate: new Date("2020-01-01"), + registerDate: new Date('2020-01-01'), } const mockUpdate = { - "code": "sequence#PI#2024", - "updatedBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "createdIp": "127.0.0.1", - "tenantCode": "MBC", - "type": "sequence", - "createdAt": "2024-11-27T17:45:45+07:00", - "updatedIp": "127.0.0.1", - "createdBy": "92ca4f68-9ac6-4080-9ae2-2f02a86206a4", - "requestId": "9fc8d555-f200-4f5d-b3e0-07d2fa9dcd16", - "name": "fiscal_yearly", - "sk": "sequence#PI#2024", - "pk": "SEQ#MBC", - "seq": 2, - "updatedAt": "2024-11-27T17:46:36+07:00" + 'code': 'sequence#PI#2024', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T17:45:45+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '9fc8d555-f200-4f5d-b3e0-07d2fa9dcd16', + 'name': 'fiscal_yearly', + 'sk': 'sequence#PI#2024', + 'pk': 'SEQ#MBC', + 'seq': 2, + 'updatedAt': '2024-11-27T17:46:36+07:00', } - jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData); - jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate); + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) const mockSequenceResponse = new SequenceEntity({ - id: "SEQ#MBC#sequence#PI#2024", + id: 'SEQ#MBC#sequence#PI#2024', no: 2, - formattedNo: "PI-5-2", - issuedAt: new Date("2024-11-27T17:46:36+07:00"), + formattedNo: 'PI-5-2', + issuedAt: new Date('2024-11-27T17:46:36+07:00'), }) const result = await service.generateSequenceItem( { @@ -1127,13 +1126,51 @@ describe('SequencesService', () => { params: { code1: 'PI', }, - date: new Date("2024-11-27T17:46:36+07:00"), + date: new Date('2024-11-27T17:46:36+07:00'), rotateBy: RotateByEnum.FISCAL_YEARLY, }, // optionsMock - ); - expect(result).toEqual(mockSequenceResponse); + ) + expect(result).toEqual(mockSequenceResponse) }) - }); - -}); + it('should call generateSequenceItem with minimum parameters', async () => { + const mockMasterData = { + typeCode: 'sequence', + format: '%%no%%', + } + const mockUpdate = { + 'code': 'sequence#TODO#none', + 'updatedBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'createdIp': '127.0.0.1', + 'tenantCode': 'MBC', + 'type': 'sequence', + 'createdAt': '2024-11-27T13:44:15+07:00', + 'updatedIp': '127.0.0.1', + 'createdBy': '92ca4f68-9ac6-4080-9ae2-2f02a86206a4', + 'requestId': '7724a67e-ded6-4ebb-9c88-c14070e24012', + 'name': 'none', + 'sk': 'sequence#TODO#none', + 'pk': 'SEQ#MBC', + 'seq': 1, + 'updatedAt': '2024-11-27T13:44:16+07:00', + } + jest.spyOn(masterService, 'getData').mockResolvedValue(mockMasterData) + jest.spyOn(dynamoDbService, 'updateItem').mockResolvedValue(mockUpdate) + const mockSequenceResponse = new SequenceEntity({ + id: 'SEQ#MBC#sequence#TODO#none', + no: 1, + formattedNo: '1', + issuedAt: new Date('2024-11-27T13:44:16+07:00'), + }) + const result = await service.generateSequenceItem( + { + tenantCode: tenantCode, + typeCode: 'sequence', + date: new Date('2024-11-27T13:44:16+07:00'), + }, + optionsMock, + ) + expect(result).toEqual(mockSequenceResponse) + }) + }) +}) diff --git a/packages/sequence/src/sequences.service.ts b/packages/sequence/src/sequences.service.ts index 598c2fa..9744f1b 100644 --- a/packages/sequence/src/sequences.service.ts +++ b/packages/sequence/src/sequences.service.ts @@ -151,7 +151,9 @@ export class SequencesService implements ISequenceService { }) const sourceIp = options?.invokeContext?.event?.requestContext?.http?.sourceIp - const userContext = options ? getUserContext(options.invokeContext) : undefined + const userContext = options + ? getUserContext(options.invokeContext) + : undefined const userId = userContext?.userId || 'system' const rotateVal = this.getRotateValue(rotateBy, date) @@ -284,7 +286,6 @@ export class SequencesService implements ISequenceService { const { now, startMonth = 4, registerTime } = options - const effectiveStartMonth = registerTime ? registerTime.getMonth() + 1 : startMonth ?? 4