-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b0ff0e
commit 4a15fb3
Showing
19 changed files
with
418 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,15 @@ | ||
import { getDatabaseCollection, getDatabaseClient } from '@rovacc/clients' | ||
|
||
export const deleteCollection1 = async (collection: string): Promise<void> => { | ||
const collectionRef = getDatabaseCollection(collection) | ||
const docs = await collectionRef.listDocuments() | ||
const deletePromises = docs.map(async (doc) => await doc.delete()) | ||
console.log(deletePromises[0].then(console.log).catch(console.error)); | ||
await Promise.all(deletePromises) | ||
console.log('=============') | ||
} | ||
|
||
|
||
export async function deleteCollection(collectionPath: string) { | ||
const db = getDatabaseClient() | ||
const collectionRef = getDatabaseCollection(collectionPath) | ||
const query = collectionRef.orderBy('__name__').limit(100); | ||
|
||
return new Promise((resolve, reject) => { | ||
deleteQueryBatch(db, query, resolve).catch(reject); | ||
}); | ||
} | ||
|
||
async function deleteQueryBatch(db, query, resolve) { | ||
const snapshot = await query.get(); | ||
|
||
const batchSize = snapshot.size; | ||
if (batchSize === 0) { | ||
resolve(); | ||
return; | ||
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())); | ||
} | ||
|
||
// Delete documents in a batch | ||
const batch = db.batch(); | ||
snapshot.docs.forEach((doc) => { | ||
batch.delete(doc.ref); | ||
}); | ||
await batch.commit(); | ||
|
||
// Recurse on the next process tick, to avoid | ||
// exploding the stack. | ||
process.nextTick(() => { | ||
deleteQueryBatch(db, query, resolve); | ||
}); | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
libs/test-helpers/src/training/events/build-training-completed-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
32 changes: 32 additions & 0 deletions
32
libs/test-helpers/src/training/events/build-training-cpt-performed-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
21 changes: 21 additions & 0 deletions
21
libs/test-helpers/src/training/events/build-training-cpt-requested-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
21 changes: 21 additions & 0 deletions
21
libs/test-helpers/src/training/events/build-training-cpt-scheduled-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
19 changes: 19 additions & 0 deletions
19
libs/test-helpers/src/training/events/build-training-intent-confirmation-expired-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}) |
19 changes: 19 additions & 0 deletions
19
libs/test-helpers/src/training/events/build-training-intent-confirmation-rejected-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {}, | ||
}) |
18 changes: 18 additions & 0 deletions
18
libs/test-helpers/src/training/events/build-training-intent-confirmation-requested-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}) |
18 changes: 18 additions & 0 deletions
18
libs/test-helpers/src/training/events/build-training-intent-confirmation-responded-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}) |
23 changes: 23 additions & 0 deletions
23
libs/test-helpers/src/training/events/build-training-intent-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
22 changes: 22 additions & 0 deletions
22
libs/test-helpers/src/training/events/build-training-mentor-assigned-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
22 changes: 22 additions & 0 deletions
22
libs/test-helpers/src/training/events/build-training-mentor-reassigned-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
29 changes: 29 additions & 0 deletions
29
libs/test-helpers/src/training/events/build-training-session-performed-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
22 changes: 22 additions & 0 deletions
22
libs/test-helpers/src/training/events/build-training-session-scheduled-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) |
29 changes: 29 additions & 0 deletions
29
libs/test-helpers/src/training/events/build-training-solo-performed-event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { TrainingSoloPerformedEvent, TrainingSoloPerformedEventData } from '@rovacc/training-events-types' | ||
|
||
type Args = { | ||
trainingId: string, | ||
eventId?: string, | ||
emittedAt?: Date, | ||
override?: Partial<TrainingSoloPerformedEventData['payload']> | ||
} | ||
|
||
export const buildTrainingSoloPerformedEvent = (args: Args): TrainingSoloPerformedEvent => ({ | ||
trainingId: args.trainingId, | ||
name: 'training-solo-performed', | ||
eventId: args.eventId ?? 'event-id', | ||
emittedAt: args.emittedAt ?? new Date(), | ||
system: 'rovacc-system-id', | ||
correlationId: 'correlationId', | ||
payload: { | ||
requestedBy: { id: 200000, name: 'Requested By Name' }, | ||
passed: true, | ||
report: { | ||
purpose: "cpt_ots", | ||
workload: "light", | ||
complexity: "routine", | ||
traffic: "light", | ||
comments: 'Session went well' | ||
}, | ||
...args.override | ||
} | ||
}) |
Oops, something went wrong.