diff --git a/__tests__/unit/choreography.test.ts b/__tests__/unit/choreography.test.ts new file mode 100644 index 0000000..ac72631 --- /dev/null +++ b/__tests__/unit/choreography.test.ts @@ -0,0 +1,47 @@ +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", () => { + + checkChoreography(ChoreographyDict.DISCORD_UPDATE_CHANNELS, { + choreographyName: "DISCORD_UPDATE_CHANNELS", + transactionsLength: 2 + }) + + }) + + describe("DISCORD_SCHEDULED_JOB", () => { + + checkChoreography(ChoreographyDict.DISCORD_SCHEDULED_JOB, { + choreographyName: "DISCORD_SCHEDULED_JOB", + transactionsLength: 1 + }) + + }) + + describe("DISCORD_FETCH_MEMBERS", () => { + + checkChoreography(ChoreographyDict.DISCORD_FETCH_MEMBERS, { + choreographyName: "DISCORD_FETCH_MEMBERS", + transactionsLength: 1 + }) + + }) + +}) + 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", 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