Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed May 11, 2024
1 parent a747828 commit 3e458c0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
15 changes: 9 additions & 6 deletions packages/server/src/db.replication.test.ts
Expand Up @@ -5,20 +5,23 @@ 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(),
};

const event2 = {
...event1,
id: 'test2',
id: eventId2,
};

const beforeTest = async (extraEnv: Record<string, string> = null) => {
await beforeAllDb('db.replication', null, extraEnv);
const beforeTest = async (envValues: Record<string, string> = null) => {
await beforeAllDb('db.replication', envValues ? { envValues } : null);
await beforeEachDb();
};

Expand All @@ -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());
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/tools/dbTools.ts
Expand Up @@ -7,6 +7,7 @@ const { execCommand } = require('@joplin/tools/tool-utils');
export interface CreateDbOptions {
dropIfExists?: boolean;
autoMigrate?: boolean;
envValues?: Record<string, string>;
}

export interface DropDbOptions {
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/utils/testing/testUtils.ts
Expand Up @@ -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<string, string> = 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_);
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand Down

0 comments on commit 3e458c0

Please sign in to comment.