diff --git a/packages/server/src/db.replication.test.ts b/packages/server/src/db.replication.test.ts index dc757162e..56713b0cf 100644 --- a/packages/server/src/db.replication.test.ts +++ b/packages/server/src/db.replication.test.ts @@ -5,8 +5,11 @@ import { DatabaseConfig, DatabaseConfigClient } from './utils/types'; import { createDb } from './tools/dbTools'; import { msleep } from './utils/time'; +const eventId1 = '4f405391-bd72-4a4f-809f-344fc6cd4b31'; +const eventId2 = '4f405391-bd72-4a4f-809f-344fc6cd4b32'; + const event1: Event = { - id: 'test1', + id: eventId1, type: 1, name: 'test', created_time: Date.now(), @@ -14,11 +17,11 @@ const event1: Event = { const event2 = { ...event1, - id: 'test2', + id: eventId2, }; -const beforeTest = async (extraEnv: Record = null) => { - await beforeAllDb('db.replication', null, extraEnv); +const beforeTest = async (envValues: Record = null) => { + await beforeAllDb('db.replication', envValues ? { envValues } : null); await beforeEachDb(); }; @@ -42,7 +45,7 @@ describe('db.replication', () => { { const results = await db().select('*').from('events'); expect(results.length).toBe(1); - expect(results[0].id).toBe('test1'); + expect(results[0].id).toBe(eventId1); } await reconnectDb(db()); @@ -51,7 +54,7 @@ describe('db.replication', () => { { const results = await db().select('*').from('events'); expect(results.length).toBe(2); - expect([results[0].id, results[1].id].sort()).toEqual(['test1', 'test2']); + expect([results[0].id, results[1].id].sort()).toEqual([eventId1, eventId2]); } await afterTest(); diff --git a/packages/server/src/tools/dbTools.ts b/packages/server/src/tools/dbTools.ts index 5cacfd3a1..63ed48e60 100644 --- a/packages/server/src/tools/dbTools.ts +++ b/packages/server/src/tools/dbTools.ts @@ -7,6 +7,7 @@ const { execCommand } = require('@joplin/tools/tool-utils'); export interface CreateDbOptions { dropIfExists?: boolean; autoMigrate?: boolean; + envValues?: Record; } export interface DropDbOptions { diff --git a/packages/server/src/utils/testing/testUtils.ts b/packages/server/src/utils/testing/testUtils.ts index c8b0c00bc..de628468e 100644 --- a/packages/server/src/utils/testing/testUtils.ts +++ b/packages/server/src/utils/testing/testUtils.ts @@ -76,10 +76,10 @@ export const getDatabaseClientType = () => { let createdDbPath_: string = null; let createdDbSlavePath_: string = null; -export async function beforeAllDb(unitName: string, createDbOptions: CreateDbOptions = null, extraEnv: Record = null) { +export async function beforeAllDb(unitName: string, createDbOptions: CreateDbOptions = null) { unitName = unitName.replace(/\//g, '_'); - const useDbSlave = extraEnv && extraEnv.DB_USE_SLAVE === '1'; + const useDbSlave = createDbOptions?.envValues && createDbOptions?.envValues.DB_USE_SLAVE === '1'; createdDbPath_ = `${packageRootDir}/db-test-${unitName}.sqlite`; await fs.remove(createdDbPath_); @@ -109,7 +109,7 @@ export async function beforeAllDb(unitName: string, createDbOptions: CreateDbOpt SLAVE_POSTGRES_PASSWORD: 'joplin', SUPPORT_EMAIL: 'testing@localhost', - ...extraEnv, + ...createDbOptions?.envValues, }), { tempDir: tempDir, }); @@ -118,7 +118,7 @@ export async function beforeAllDb(unitName: string, createDbOptions: CreateDbOpt SQLITE_DATABASE: createdDbPath_, SLAVE_SQLITE_DATABASE: createdDbSlavePath_, SUPPORT_EMAIL: 'testing@localhost', - ...extraEnv, + ...createDbOptions?.envValues, }), { tempDir: tempDir, });