Skip to content

Commit

Permalink
training events updated #1
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeenciu committed Jun 22, 2023
1 parent 4a15fb3 commit 5b3d43b
Show file tree
Hide file tree
Showing 27 changed files with 84 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TrainingMentorAssignedEventData = {
trainingId: string
payload: {
mentor: Member
assigned_by: Member
assignedBy: Member
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type TrainingMentorReassignedEventData = {
trainingId: string
payload: {
mentor: Member
assigned_by: Member
assignedBy: Member
}
}

Expand Down
60 changes: 34 additions & 26 deletions libs/training-events/src/actions/emit-training-event.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, it, expect } from "vitest";
import { TrainingEventData } from "../types";
import { TrainingEventData } from "@rovacc/training-events-types";

import { emitTrainingEvent } from "./emit-training-event";
import { deleteCollection } from "@rovacc/test-helpers";
Expand Down Expand Up @@ -27,7 +27,7 @@ describe('emitTrainingEvent', () => {
vi.restoreAllMocks()
})

it('should emit the event correctly', async () => {
it('should emit the event correctly and create the empty training object', async () => {
const eventData: TrainingEventData = {
trainingId: TRAINING_ID,
name: 'training-intent',
Expand Down Expand Up @@ -62,37 +62,45 @@ describe('emitTrainingEvent', () => {
})
})

it('should emit the event', async () => {
const eventData: TrainingEventData = {
trainingId: TRAINING_ID,
name: 'training-intent',
payload: {
student: 1364858,
rating: 5,
purpose: 'acquire_rating'
}
}

const reducedTraining = await emitTrainingEvent(eventData, null, 'correlationId')
it('should emit the event and not alter the training object', async () => {

expect(reducedTraining).toEqual({
trainingId: TRAINING_ID,
status: 'QUEUED',
const trainingCollection = getDatabaseCollection('training')
await trainingCollection.doc(TRAINING_ID).set({
purpose: 'acquire_rating',
rating: 5,
student: 1364858,
requestedAt: DATE
})
const trainingCollection = getDatabaseCollection('training')
await trainingCollection.doc(TRAINING_ID).collection('events').doc('event-id').set({
const eventData: TrainingEventData = {
trainingId: TRAINING_ID,
name: 'training-test-completed',
payload: {
passed: true,
result: 'passed',
willExpireAt: new Date()
}
}

const reducedTraining = await emitTrainingEvent(eventData, null, 'correlationId')

expect(reducedTraining).toEqual({
trainingId: TRAINING_ID,
status: 'QUEUED',
purpose: 'acquire_rating',
rating: 5,
student: 1364858,
requestedAt: DATE
})
const event = await trainingCollection.doc(TRAINING_ID).collection('events').doc(EVENT_ID).get()
expect(event.data()).toEqual({
eventId: EVENT_ID,
emittedAt: Timestamp.fromDate(DATE),
system: 'rovacc-system-id',
trainingId: TRAINING_ID,
payload: { student: 1364858, purpose: 'acquire_rating', rating: 5 },
name: 'training-intent',
correlationId: 'correlationId'
})
eventId: EVENT_ID,
emittedAt: Timestamp.fromDate(DATE),
system: 'rovacc-system-id',
trainingId: TRAINING_ID,
payload: { student: 1364858, purpose: 'acquire_rating', rating: 5 },
name: 'training-intent',
correlationId: 'correlationId'
})
})
})
2 changes: 1 addition & 1 deletion libs/training-events/src/actions/emit-training-event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { v4 as uuidv4 } from "uuid";
import { Training, TrainingEvent, TrainingEventData } from "../types";
import { Training, TrainingEvent, TrainingEventData } from "@rovacc/training-events-types";
import { SYSTEM_ID, TRAINING_COLLECTION, TRAINING_EVENTS_SUBCOLLECTION } from '../config'
import { getDatabaseCollection } from '@rovacc/clients'
import { isEmitted, reduceEvent } from "../events";
Expand Down
2 changes: 1 addition & 1 deletion libs/training-events/src/actions/get-training-events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDatabaseCollection } from "@rovacc/clients";
import { Training, TrainingEvent } from "../types";
import { Training, TrainingEvent } from "@rovacc/training-events-types";
import { TRAINING_COLLECTION, TRAINING_EVENTS_SUBCOLLECTION } from "../config";
import { TrainingNotFound } from "../exception/training-not-found";

Expand Down
2 changes: 1 addition & 1 deletion libs/training-events/src/events/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsEmitted, Reducer, Training, TrainingEvent } from "../types";
import { IsEmitted, Reducer, Training, TrainingEvent } from "@rovacc/training-events-types";
import { trainingCompleted } from "./training-completed";
import { trainingCptPerformed } from "./training-cpt-performed";
import { trainingCptRequested } from "./training-cpt-requested";
Expand Down
13 changes: 1 addition & 12 deletions libs/training-events/src/events/training-completed.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@

import { OutcomeReason, OutcomeReasonDetailed, Reducer, Training, TrainingEventMetadata } from "../types";
import { TrainingCompletedEvent, Reducer, Training } from "@rovacc/training-events-types";

const name = 'training-completed'

export type TrainingCompletedEventData = {
trainingId: string,
name: typeof name
payload: {
reason: OutcomeReason
reasonDetailed: OutcomeReasonDetailed
}
}

export type TrainingCompletedEvent = TrainingEventMetadata & TrainingCompletedEventData

const reducer: Reducer<TrainingCompletedEvent> = (
training: Training | null,
event: TrainingCompletedEvent
Expand Down
14 changes: 1 addition & 13 deletions libs/training-events/src/events/training-cpt-performed.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@

import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from "../types";
import { Reducer, Training, TrainingCptPerformedEvent } from "@rovacc/training-events-types";

const name = 'training-cpt-performed'

export type TrainingCptPerformedEventData = {
trainingId: string,
name: typeof name
payload: {
assessedBy: Member
report: TrainingReport
passed: boolean
}
}

export type TrainingCptPerformedEvent = TrainingEventMetadata & TrainingCptPerformedEventData

const reducer: Reducer<TrainingCptPerformedEvent> = (
training: Training | null,
event: TrainingCptPerformedEvent
Expand Down
12 changes: 1 addition & 11 deletions libs/training-events/src/events/training-cpt-requested.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@

import { Member, Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingCptRequestedEvent } from "@rovacc/training-events-types";

const name = 'training-cpt-requested'

export type TrainingCptRequestedEventData = {
trainingId: string,
name: typeof name
payload: {
requestedBy: Member
}
}

export type TrainingCptRequestedEvent = TrainingEventMetadata & TrainingCptRequestedEventData

const reducer: Reducer<TrainingCptRequestedEvent> = (
training: Training | null,
event: TrainingCptRequestedEvent
Expand Down
12 changes: 1 addition & 11 deletions libs/training-events/src/events/training-cpt-scheduled.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@

import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingCptScheduledEvent } from "@rovacc/training-events-types";

const name = 'training-cpt-scheduled'

export type TrainingCptScheduledEventData = {
trainingId: string,
name: typeof name
payload: {
scheduledAt: Date
}
}

export type TrainingCptScheduledEvent = TrainingEventMetadata & TrainingCptScheduledEventData

const reducer: Reducer<TrainingCptScheduledEvent> = (
training: Training | null,
event: TrainingCptScheduledEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@

import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingIntentConfirmationExpiredEvent } from "@rovacc/training-events-types";

const name = 'training-intent-confirmation-expired';

export type TrainingIntentConfirmationExpiredEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationExpiredEvent = TrainingEventMetadata & TrainingIntentConfirmationExpiredEventData

const reducer: Reducer<TrainingIntentConfirmationExpiredEvent> = (
training: Training | null,
event: TrainingIntentConfirmationExpiredEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingIntentConfirmationRejectedEvent } from "@rovacc/training-events-types";

const name = 'training-intent-confirmation-rejected';

export type TrainingIntentConfirmationRejectedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRejectedEvent = TrainingEventMetadata & TrainingIntentConfirmationRejectedEventData

const reducer: Reducer<TrainingIntentConfirmationRejectedEvent> = (
training: Training | null,
event: TrainingIntentConfirmationRejectedEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@

import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingIntentConfirmationRequestedEvent } from "@rovacc/training-events-types";

const name = 'training-intent-confirmation-requested';

export type TrainingIntentConfirmationRequestedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRequestedEvent = TrainingEventMetadata & TrainingIntentConfirmationRequestedEventData

const reducer: Reducer<TrainingIntentConfirmationRequestedEvent> = (
training: Training | null,
event: TrainingIntentConfirmationRequestedEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@

import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingIntentConfirmationRespondedEvent } from "@rovacc/training-events-types";

const name = 'training-intent-confirmation-responded';

export type TrainingIntentConfirmationRespondedEventData = {
name: typeof name
trainingId: string
payload: Record<string, never>
}

export type TrainingIntentConfirmationRespondedEvent = TrainingEventMetadata & TrainingIntentConfirmationRespondedEventData

const reducer: Reducer<TrainingIntentConfirmationRespondedEvent> = (
training: Training | null,
event: TrainingIntentConfirmationRespondedEvent
Expand Down
14 changes: 1 addition & 13 deletions libs/training-events/src/events/training-intent.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@

import { Reducer, Training, TrainingEventMetadata, TrainingPurpose } from "../types";
import { Reducer, Training, TrainingIntentEvent } from "@rovacc/training-events-types";

const name = 'training-intent';

export type TrainingIntentEventData = {
trainingId: string,
name: typeof name
payload: {
student: number
rating: number
purpose: TrainingPurpose
}
}

export type TrainingIntentEvent = TrainingEventMetadata & TrainingIntentEventData

const reducer: Reducer<TrainingIntentEvent> = (
training: Training | null,
event: TrainingIntentEvent
Expand Down
15 changes: 2 additions & 13 deletions libs/training-events/src/events/training-mentor-assigned.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { Member, Reducer, Training, TrainingEventMetadata } from "../types";
import { Member, Reducer, Training, TrainingMentorAssignedEvent } from "@rovacc/training-events-types";

const name = 'training-mentor-assigned'

export type TrainingMentorAssignedEventData = {
name: typeof name
trainingId: string
payload: {
mentor: Member
assigned_by: Member
}
}

export type TrainingMentorAssignedEvent = TrainingEventMetadata & TrainingMentorAssignedEventData

const reducer: Reducer<TrainingMentorAssignedEvent> = (
training: Training | null,
event: TrainingMentorAssignedEvent
Expand All @@ -23,7 +12,7 @@ const reducer: Reducer<TrainingMentorAssignedEvent> = (
mentor: {
member: event.payload.mentor,
assignedAt: event.emittedAt,
assignedBy: event.payload.assigned_by,
assignedBy: event.payload.assignedBy,
}
})

Expand Down
15 changes: 2 additions & 13 deletions libs/training-events/src/events/training-mentor-reassigned.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { Member, Reducer, Training, TrainingEventMetadata } from "../types";
import { Member, Reducer, Training, TrainingMentorReassignedEvent } from "@rovacc/training-events-types";

const name = 'training-mentor-reassigned'

export type TrainingMentorReassignedEventData = {
name: typeof name
trainingId: string
payload: {
mentor: Member
assigned_by: Member
}
}

export type TrainingMentorReassignedEvent = TrainingEventMetadata & TrainingMentorReassignedEventData

const reducer: Reducer<TrainingMentorReassignedEvent> = (
training: Training | null,
event: TrainingMentorReassignedEvent
Expand All @@ -23,7 +12,7 @@ const reducer: Reducer<TrainingMentorReassignedEvent> = (
mentor: {
member: event.payload.mentor,
assignedAt: event.emittedAt,
assignedBy: event.payload.assigned_by,
assignedBy: event.payload.assignedBy,
}
})

Expand Down
14 changes: 1 addition & 13 deletions libs/training-events/src/events/training-session-performed.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import { Member, Reducer, Training, TrainingEventMetadata, TrainingReport } from "../types";
import { Reducer, Training, TrainingSessionPerformedEvent } from "@rovacc/training-events-types";

const name = 'training-session-performed'

export type TrainingSessionPerformedEventData = {
name: typeof name
trainingId: string
payload: {
sessionId: string
mentor: Member,
report: TrainingReport
}
}

export type TrainingSessionPerformedEvent = TrainingEventMetadata & TrainingSessionPerformedEventData

const reducer: Reducer<TrainingSessionPerformedEvent> = (
training: Training | null,
event: TrainingSessionPerformedEvent
Expand Down
13 changes: 1 addition & 12 deletions libs/training-events/src/events/training-session-scheduled.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { Reducer, Training, TrainingEventMetadata } from "../types";
import { Reducer, Training, TrainingSessionScheduledEvent } from "@rovacc/training-events-types";

const name = 'training-session-scheduled'

export type TrainingSessionScheduledEventData = {
name: typeof name
trainingId: string
payload: {
sessionId: string
scheduledAt: Date
}
}

export type TrainingSessionScheduledEvent = TrainingEventMetadata & TrainingSessionScheduledEventData

const reducer: Reducer<TrainingSessionScheduledEvent> = (
training: Training | null,
event: TrainingSessionScheduledEvent
Expand Down
Loading

0 comments on commit 5b3d43b

Please sign in to comment.