From b5b24f7bf8b40a4efa9d8b54255f3ae631a48b57 Mon Sep 17 00:00:00 2001 From: Daniel Dias Branco Arthaud Date: Thu, 18 Aug 2022 22:12:01 -0300 Subject: [PATCH] test with mysql8 Signed-off-by: Daniel Dias Branco Arthaud --- packages/backend-tasks/src/tasks/util.test.ts | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/packages/backend-tasks/src/tasks/util.test.ts b/packages/backend-tasks/src/tasks/util.test.ts index 614de8c6c8..ceeeba14d6 100644 --- a/packages/backend-tasks/src/tasks/util.test.ts +++ b/packages/backend-tasks/src/tasks/util.test.ts @@ -14,9 +14,16 @@ * limitations under the License. */ +import knexFactory, { Knex } from 'knex'; import { Duration } from 'luxon'; import { AbortController } from 'node-abort-controller'; -import { delegateAbortController, sleep, validateId } from './util'; +import { delegateAbortController, nowPlus, sleep, validateId } from './util'; + +class KnexBuilder { + public build(client: string): Knex { + return knexFactory({ client }); + } +} describe('util', () => { describe('validateId', () => { @@ -73,4 +80,35 @@ describe('util', () => { expect(child.signal.aborted).toBe(true); }); }); + + describe('nowPlus', () => { + describe('without duration', () => { + const databases = [ + { client: 'sqlite3', expected: 'CURRENT_TIMESTAMP' }, + { client: 'mysql2', expected: 'CURRENT_TIMESTAMP' }, + { client: 'pg', expected: 'CURRENT_TIMESTAMP' }, + ]; + + it.each(databases)('for client $client', ({ client, expected }) => { + const knex = new KnexBuilder().build(client); + const result = nowPlus(undefined, knex); + + expect(result.toString()).toBe(expected); + }); + }); + describe('With duration', () => { + const databases = [ + { client: 'sqlite3', expected: "datetime('now', '20 seconds')" }, + { client: 'mysql2', expected: 'now() + interval 20 second' }, + { client: 'pg', expected: "now() + interval '20 seconds'" }, + ]; + it.each(databases)('for client $client', ({ client, expected }) => { + const duration = Duration.fromObject({ seconds: 20 }); + const knex = new KnexBuilder().build(client); + const result = nowPlus(duration, knex); + + expect(result.toString()).toBe(expected); + }); + }); + }); });