From da7cc580a58e7d39aac7f15775438cc28a7ab83e Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Tue, 13 Jun 2023 16:51:58 +0400 Subject: [PATCH 1/4] feat: DISCORD_FETCH_MEMBERS choreography was added to the package --- src/enums/event.enum.ts | 1 + src/saga/choreography.ts | 10 ++++++++-- src/saga/transaction.ts | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/enums/event.enum.ts b/src/enums/event.enum.ts index 4c54865..793644c 100644 --- a/src/enums/event.enum.ts +++ b/src/enums/event.enum.ts @@ -19,6 +19,7 @@ const ServerEvent = { const DiscordBotEvent = { ...BotEvent, SEND_MESSAGE: 'SEND_MESSAGE', + FETCH_MEMBERS: 'FETCH_MEMBERS', }; const DiscordAnalyzerEvent = { diff --git a/src/saga/choreography.ts b/src/saga/choreography.ts index 56f399b..806d426 100644 --- a/src/saga/choreography.ts +++ b/src/saga/choreography.ts @@ -1,5 +1,5 @@ import { IChoreography } from '../interfaces/choreography.interface'; -import { DISCORD_SCHEDULED_JOB_TRANSACTIONS, DISCORD_UPDATE_CHANNELS_TRANSACTIONS } from './transaction'; +import { DISCORD_FETCH_MEMBERS_TRANSACTIONS, DISCORD_SCHEDULED_JOB_TRANSACTIONS, DISCORD_UPDATE_CHANNELS_TRANSACTIONS } from './transaction'; /* define the DISCORD_UPDATE_CHANNELS choreography */ const DISCORD_UPDATE_CHANNELS: IChoreography = { @@ -13,8 +13,14 @@ const DISCORD_SCHEDULED_JOB: IChoreography = { transactions: DISCORD_SCHEDULED_JOB_TRANSACTIONS, }; +const DISCORD_FETCH_MEMBERS: IChoreography = { + name: 'DISCORD_FETCH_MEMBERS', + transactions: DISCORD_FETCH_MEMBERS_TRANSACTIONS +} + /* all available Choreographies, will grow overtime */ export const ChoreographyDict = { DISCORD_UPDATE_CHANNELS, - DISCORD_SCHEDULED_JOB + DISCORD_SCHEDULED_JOB, + DISCORD_FETCH_MEMBERS } as const; diff --git a/src/saga/transaction.ts b/src/saga/transaction.ts index ddadab2..3a79aa7 100644 --- a/src/saga/transaction.ts +++ b/src/saga/transaction.ts @@ -42,3 +42,13 @@ export const DISCORD_SCHEDULED_JOB_TRANSACTIONS: ITransaction[] = [ ...DEFAULT_TRANSACTION_PROPERTY, }, ]; + +export const DISCORD_FETCH_MEMBERS_TRANSACTIONS: ITransaction[] = [ + { + queue: Queue.DISCORD_BOT, + event: Event.DISCORD_BOT.FETCH_MEMBERS, + order: 1, + status: Status.NOT_STARTED, + ...DEFAULT_TRANSACTION_PROPERTY, + }, +] \ No newline at end of file From d9b836878083c7665bdedb9be9b1a858100d1858 Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Tue, 13 Jun 2023 16:52:29 +0400 Subject: [PATCH 2/4] version increased --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2266ffb..92d0e9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@togethercrew.dev/tc-messagebroker", - "version": "0.0.38", + "version": "0.0.39", "description": "a service that include common things that need in every microservies ", "main": "./dist/index.js", "types": "./dist/index.d.ts", From 85bb2bc5031fe567a650c5a5b415e7efc6cf3c29 Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Thu, 15 Jun 2023 16:42:29 +0400 Subject: [PATCH 3/4] tests: tests was added for choreography --- __tests__/unit/choreography.test.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 __tests__/unit/choreography.test.ts diff --git a/__tests__/unit/choreography.test.ts b/__tests__/unit/choreography.test.ts new file mode 100644 index 0000000..f63c4c9 --- /dev/null +++ b/__tests__/unit/choreography.test.ts @@ -0,0 +1,42 @@ +import { ChoreographyDict } from '../../src'; + +describe('choreography exists', () => { + + describe("DISCORD_UPDATE_CHANNELS", () => { + it("exists", () => { + expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS).toBeDefined() + }) + it("have proper name", () => { + expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS.name).toBe("DISCORD_UPDATE_CHANNELS") + }) + it("have expected steps", () => { + expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS.transactions.length).toBe(2) + }) + }) + + describe("DISCORD_SCHEDULED_JOB", () => { + it("exists", () => { + expect(ChoreographyDict.DISCORD_SCHEDULED_JOB).toBeDefined() + }) + it("have proper name", () => { + expect(ChoreographyDict.DISCORD_SCHEDULED_JOB.name).toBe("DISCORD_SCHEDULED_JOB") + }) + it("have expected steps", () => { + expect(ChoreographyDict.DISCORD_SCHEDULED_JOB.transactions.length).toBe(1) + }) + }) + + describe("DISCORD_FETCH_MEMBERS", () => { + it("exists", () => { + expect(ChoreographyDict.DISCORD_FETCH_MEMBERS).toBeDefined() + }) + it("have proper name", () => { + expect(ChoreographyDict.DISCORD_FETCH_MEMBERS.name).toBe("DISCORD_FETCH_MEMBERS") + }) + it("have expected steps", () => { + expect(ChoreographyDict.DISCORD_FETCH_MEMBERS.transactions.length).toBe(1) + }) + }) + +}) + From 7d8da56dc030ff1ddf1bd768718c6f3502bf73ab Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Thu, 15 Jun 2023 16:50:54 +0400 Subject: [PATCH 4/4] tests: make tests more clear --- __tests__/unit/choreography.test.ts | 55 ++++++++++++++++------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/__tests__/unit/choreography.test.ts b/__tests__/unit/choreography.test.ts index f63c4c9..ac72631 100644 --- a/__tests__/unit/choreography.test.ts +++ b/__tests__/unit/choreography.test.ts @@ -1,41 +1,46 @@ -import { ChoreographyDict } from '../../src'; +import { ChoreographyDict, IChoreography } from '../../src'; + +function checkChoreography(choreography: IChoreography, toBe: {choreographyName: string, transactionsLength: number}){ + it("exists", () => { + expect(choreography).toBeDefined() + }) + + it("have proper name", () => { + expect(choreography.name).toBe(toBe.choreographyName) + }) + + it("have expected steps", () => { + expect(choreography.transactions.length).toBe(toBe.transactionsLength) + }) +} describe('choreography exists', () => { describe("DISCORD_UPDATE_CHANNELS", () => { - it("exists", () => { - expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS).toBeDefined() - }) - it("have proper name", () => { - expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS.name).toBe("DISCORD_UPDATE_CHANNELS") - }) - it("have expected steps", () => { - expect(ChoreographyDict.DISCORD_UPDATE_CHANNELS.transactions.length).toBe(2) + + checkChoreography(ChoreographyDict.DISCORD_UPDATE_CHANNELS, { + choreographyName: "DISCORD_UPDATE_CHANNELS", + transactionsLength: 2 }) + }) describe("DISCORD_SCHEDULED_JOB", () => { - it("exists", () => { - expect(ChoreographyDict.DISCORD_SCHEDULED_JOB).toBeDefined() - }) - it("have proper name", () => { - expect(ChoreographyDict.DISCORD_SCHEDULED_JOB.name).toBe("DISCORD_SCHEDULED_JOB") - }) - it("have expected steps", () => { - expect(ChoreographyDict.DISCORD_SCHEDULED_JOB.transactions.length).toBe(1) + + checkChoreography(ChoreographyDict.DISCORD_SCHEDULED_JOB, { + choreographyName: "DISCORD_SCHEDULED_JOB", + transactionsLength: 1 }) + }) describe("DISCORD_FETCH_MEMBERS", () => { - it("exists", () => { - expect(ChoreographyDict.DISCORD_FETCH_MEMBERS).toBeDefined() - }) - it("have proper name", () => { - expect(ChoreographyDict.DISCORD_FETCH_MEMBERS.name).toBe("DISCORD_FETCH_MEMBERS") - }) - it("have expected steps", () => { - expect(ChoreographyDict.DISCORD_FETCH_MEMBERS.transactions.length).toBe(1) + + checkChoreography(ChoreographyDict.DISCORD_FETCH_MEMBERS, { + choreographyName: "DISCORD_FETCH_MEMBERS", + transactionsLength: 1 }) + }) })