( actual: string, expected: string, joinsOrArgCount: Record<string, string> | number, argCount?: number, )
| 47 | } |
| 48 | |
| 49 | async function assertEqual( |
| 50 | actual: string, |
| 51 | expected: string, |
| 52 | joinsOrArgCount: Record<string, string> | number, |
| 53 | argCount?: number, |
| 54 | ) { |
| 55 | const i = { i: 0 } |
| 56 | const expected2 = await format(expected) |
| 57 | const ky = new Kysely<DB>({ |
| 58 | // @ts-expect-error don't actually use CRDialect |
| 59 | dialect: new CRDialect(), |
| 60 | }) |
| 61 | const converted = actualConvert(actual, new Date()) |
| 62 | const compile = converted.sql!.compile(ky) |
| 63 | const actual2 = unparameterize(i, compile) |
| 64 | expect(await format(actual2)).toBe(expected2) |
| 65 | if (typeof joinsOrArgCount === 'number') { |
| 66 | expect(i.i).toBe(joinsOrArgCount) |
| 67 | } else { |
| 68 | async function testJoin( |
| 69 | list: Array<{ |
| 70 | sql: RawBuilder<SqlBool> |
| 71 | name: string |
| 72 | }>, |
| 73 | ) { |
| 74 | for (const x of list) { |
| 75 | const compile = x.sql.compile(ky) |
| 76 | const p = unparameterize(i, compile) |
| 77 | const expected = |
| 78 | (joinsOrArgCount as Record<string, string>)[x.name] ?? |
| 79 | throwExp(x.name + " can't be null dude") |
| 80 | expect(await format(p)).toEqual(await format(expected)) |
| 81 | } |
| 82 | } |
| 83 | await testJoin(converted.joinNoteValueFts) |
| 84 | await testJoin(converted.joinNoteFieldValue) |
| 85 | await testJoin(converted.joinCardTagFts) |
| 86 | await testJoin(converted.joinNoteTagFts) |
| 87 | await testJoin(converted.joinCardTag) |
| 88 | await testJoin(converted.joinNoteTag) |
| 89 | expect(argCount).not.toBeUndefined() |
| 90 | expect(i.i).toBe(argCount) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | test('empty string is null', () => { |
| 95 | const sql = actualConvert('', new Date()).sql |
no test coverage detected