Skip to content

Commit

Permalink
test helpers #1
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeenciu committed Jul 8, 2023
1 parent 9b453e5 commit 7257ada
Show file tree
Hide file tree
Showing 30 changed files with 617 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libs/test-helpers/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/test-helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# test-helpers

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build test-helpers` to build the library.

## Running unit tests

Run `nx test test-helpers` to execute the unit tests via [Jest](https://jestjs.io).
5 changes: 5 additions & 0 deletions libs/test-helpers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@rovacc/test-helpers",
"version": "0.0.1",
"type": "commonjs"
}
31 changes: 31 additions & 0 deletions libs/test-helpers/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "test-helpers",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/test-helpers/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/test-helpers"
}
},
"test": {
"executor": "@nx/vite:test",
"outputs": ["coverage/libs/test-helpers"],
"options": {
"passWithNoTests": true,
"reportsDirectory": "../../coverage/libs/test-helpers"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/test-helpers/**/*.ts"]
}
}
},
"tags": []
}
15 changes: 15 additions & 0 deletions libs/test-helpers/src/firestore/delete-collection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export async function deleteCollection(collectionPath: string) {
const endpoint = process.env['FIRESTORE_EMULATOR_HOST'] as string
const project = process.env['GCLOUD_PROJECT'] as string

const response = await fetch(
`http://${endpoint}/emulator/v1/projects/${project}/databases/(default)/documents/${collectionPath}`,
{
method: 'DELETE',
}
);
if (response.status !== 200) {
throw new Error('Trouble clearing Emulator: ' + (await response.text()));
}
}

1 change: 1 addition & 0 deletions libs/test-helpers/src/firestore/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { deleteCollection } from './delete-collection'
2 changes: 2 additions & 0 deletions libs/test-helpers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './firestore'
export * from './training/events'
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TrainingCompletedEvent, TrainingCompletedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingCompletedEventData['payload']>
}

export const buildTrainingCompletedEvent = (args: Args): TrainingCompletedEvent => ({
trainingId: args.trainingId,
name: 'training-completed',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
reason: 'completed',
reasonDetailed: 'rating_upgraded',
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { TrainingCptPerformedEvent, TrainingCptPerformedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingCptPerformedEventData['payload']>
}

export const buildTrainingCptPerformedEvent = (args: Args): TrainingCptPerformedEvent => ({
trainingId: args.trainingId,
name: 'training-cpt-performed',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
assessedBy: {
id: 200200,
name: 'member-name'
},
report: {
purpose: "cpt_ots",
workload: "light",
complexity: "routine",
traffic: "light",
comments: 'Session went well'
},
passed: true,
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TrainingCptRequestedEvent } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingCptRequestedEvent['payload']>
}

export const buildTrainingCptRequestedEvent = (args: Args): TrainingCptRequestedEvent => ({
trainingId: args.trainingId,
name: 'training-cpt-requested',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
requestedBy: { id: 123123, name: 'Requested By Name' },
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TrainingCptScheduledEvent } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingCptScheduledEvent['payload']>
}

export const buildTrainingCptScheduledEvent = (args: Args): TrainingCptScheduledEvent => ({
trainingId: args.trainingId,
name: 'training-cpt-scheduled',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
scheduledAt: new Date(),
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TrainingIntentConfirmationExpiredEvent, TrainingIntentConfirmationExpiredEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingIntentConfirmationExpiredEventData['payload']>
}

export const buildTrainingIntentConfirmationExpiredEvent =
(args: Args): TrainingIntentConfirmationExpiredEvent => ({
name: 'training-intent-confirmation-expired',
trainingId: args.trainingId,
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TrainingIntentConfirmationRejectedEvent, TrainingIntentConfirmationRejectedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingIntentConfirmationRejectedEventData['payload']>
}

export const buildTrainingIntentConfirmationRejectedEvent =
(args: Args): TrainingIntentConfirmationRejectedEvent => ({
name: 'training-intent-confirmation-rejected',
trainingId: args.trainingId,
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TrainingIntentConfirmationRequestedEvent, TrainingIntentConfirmationRequestedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingIntentConfirmationRequestedEventData['payload']>
}

export const buildTrainingIntentConfirmationRequestedEvent = (args: Args): TrainingIntentConfirmationRequestedEvent => ({
trainingId: args.trainingId,
name: 'training-intent-confirmation-requested',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TrainingIntentConfirmationRespondedEvent, TrainingIntentConfirmationRespondedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingIntentConfirmationRespondedEventData['payload']>
}

export const buildTrainingIntentConfirmationRespondedEvent = (args: Args): TrainingIntentConfirmationRespondedEvent => ({
trainingId: args.trainingId,
name: 'training-intent-confirmation-responded',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TrainingIntentEvent } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingIntentEvent>
}

export const buildTrainingIntentEvent = (args: Args): TrainingIntentEvent => ({
trainingId: args.trainingId,
name: 'training-intent',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
student: 123123123,
rating: 2,
purpose: 'acquire_rating',
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TrainingMentorAssignedEvent, TrainingMentorAssignedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingMentorAssignedEventData['payload']>
}

export const buildTrainingMentorAssignedEvent = (args: Args): TrainingMentorAssignedEvent => ({
trainingId: args.trainingId,
name: 'training-mentor-assigned',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
mentor: { id: 200000, name: 'Mentor Name' },
assignedBy: { id: 200200, name: 'Assigned By Name' },
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TrainingMentorReassignedEvent, TrainingMentorReassignedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingMentorReassignedEventData['payload']>
}

export const buildTrainingMentorReassignedEvent = (args: Args): TrainingMentorReassignedEvent => ({
trainingId: args.trainingId,
name: 'training-mentor-reassigned',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
mentor: { id: 200000, name: 'Mentor Name' },
assignedBy: { id: 200200, name: 'Assigned By Name' },
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { TrainingSessionPerformedEvent, TrainingSessionPerformedEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingSessionPerformedEventData['payload']>
}

export const buildTrainingSessionPerformedEvent = (args: Args): TrainingSessionPerformedEvent => ({
trainingId: args.trainingId,
name: 'training-session-performed',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
sessionId: 'session-id',
mentor: { id: 200000, name: 'Mentor Name' },
report: {
purpose: "cpt_ots",
workload: "light",
complexity: "routine",
traffic: "light",
comments: 'Session went well'
},
...args.override
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { TrainingSessionScheduledEvent, TrainingSessionScheduledEventData } from '@rovacc/training-events-types'

type Args = {
trainingId: string,
eventId?: string,
emittedAt?: Date,
override?: Partial<TrainingSessionScheduledEventData['payload']>
}

export const buildTrainingSessionScheduledEvent = (args: Args): TrainingSessionScheduledEvent => ({
trainingId: args.trainingId,
name: 'training-session-scheduled',
eventId: args.eventId ?? 'event-id',
emittedAt: args.emittedAt ?? new Date(),
system: 'rovacc-system-id',
correlationId: 'correlationId',
payload: {
sessionId: 'session-id',
scheduledAt: new Date(),
...args.override
}
})
Loading

0 comments on commit 7257ada

Please sign in to comment.