1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

fixed tests

This commit is contained in:
Laurent Cozic 2024-05-11 17:24:51 +01:00
parent a747828276
commit 3e458c0028
3 changed files with 14 additions and 10 deletions

View File

@ -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<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();
};
@ -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();

View File

@ -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 {

View File

@ -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_);
@ -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,
});