Skip to content

Commit

Permalink
Document util function
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarvarela committed Dec 9, 2024
1 parent 951645a commit ce77f92
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions site/gatsby-site/playwright/memory-mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,28 @@ import reportsHistory from './seeds/history/reportsHistory';
import incidentsHistory from './seeds/history/incidentsHistory';
import checklists from './seeds/aiidprod/checklists';

export const init = async (extra?: Record<string, Record<string, Record<string, unknown>[]>>, { drop } = { drop: false }) => {
/**
* Initializes a MongoDB database with predefined and optional custom seed data.
*
* @param {Record<string, Record<string, Record<string, unknown>[]>>} [seed] - Optional additional seed data
* organized as database -> collection -> documents structure.
* Example: { database1: { collection1: [ doc1, doc2 ] } }
* @param {Object} [options={ drop: false }] - Configuration options
* @param {boolean} [options.drop=false] - Whether to drop existing collections before seeding
* @returns {Promise<void>} A promise that resolves when seeding is complete
*
* @example
* // Initialize with default data only
* await init();
*
* // Initialize with default data and deletes whats in myCollection
* await init({
* myDatabase: {
* myCollection: [{ field: 'value' }]
* }
* }, { drop: true });
*/
export const init = async (seed?: Record<string, Record<string, Record<string, unknown>[]>>, { drop } = { drop: false }) => {

await seedFixture({
aiidprod: {
Expand All @@ -46,9 +67,9 @@ export const init = async (extra?: Record<string, Record<string, Record<string,
}
});

if (extra) {
if (seed) {

await seedFixture(extra, drop);
await seedFixture(seed, drop);
}

console.log('Memory Mongo initialized');
Expand Down

0 comments on commit ce77f92

Please sign in to comment.