Skip to content

Commit

Permalink
πŸ’„βœ… backend: fix compiler issue and e2e pg connector (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlinagora committed Jul 10, 2024
1 parent 7cbb6d0 commit 5320ad6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
2 changes: 0 additions & 2 deletions tdrive/backend/node/src/services/documents/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ import archiver from "archiver";
import internal from "stream";
import config from "config";
import { randomUUID } from "crypto";
import { MultipartFile } from "@fastify/multipart";
import { UploadOptions } from "../../files/types";

export class DocumentsService {
version: "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,43 @@ describe('The PostgresQueryBuilder', () => {
const entity = newTestDbEntity();

const newValue = "new-tag-value";
const [queryText, params] = subj.buildatomicCompareAndSet(entity, "tags", null, newValue);
const queries = subj.buildatomicCompareAndSet(entity, "tags", null, newValue);
let queryText, params;

expect(normalizeWhitespace(queryText as string)).toBe(`UPDATE "test_table" SET tags = $1 WHERE company_id = $2 AND id = $3 AND tags = $4 RETURNING tags`);
[queryText, params] = queries.updateQuery;
expect(normalizeWhitespace(queryText as string)).toBe(`UPDATE "test_table" SET tags = $1 WHERE company_id = $2 AND id = $3 AND tags IS NULL`);
expect(params[0]).toBe(JSON.stringify(newValue));
expect(params[1]).toBe(entity.company_id);
expect(params[2]).toBe(entity.id);
expect(params[3]).toBe(null);
expect(params.length).toBe(3);

[queryText, params] = queries.getValueQuery;
expect(normalizeWhitespace(queryText as string)).toBe(`SELECT "tags" FROM "test_table" WHERE company_id = $1 AND id = $2`);
expect(params[0]).toBe(entity.company_id);
expect(params[1]).toBe(entity.id);
expect(params.length).toBe(2);
});

test('buildatomicCompareAndSet to null', async () => {
const entity = newTestDbEntity();

const previousValue = "new-tag-value";
const [queryText, params] = subj.buildatomicCompareAndSet(entity, "tags", previousValue, null);
const queries = subj.buildatomicCompareAndSet(entity, "tags", previousValue, null);
let queryText, params;

expect(normalizeWhitespace(queryText as string)).toBe(`UPDATE "test_table" SET tags = $1 WHERE company_id = $2 AND id = $3 AND tags = $4 RETURNING tags`);
[queryText, params] = queries.updateQuery;
expect(normalizeWhitespace(queryText as string)).toBe(`UPDATE "test_table" SET tags = $1 WHERE company_id = $2 AND id = $3 AND tags = $4`);
expect(params[0]).toBe(null);
expect(params[1]).toBe(entity.company_id);
expect(params[2]).toBe(entity.id);
expect(params[3]).toBe(JSON.stringify(previousValue));
expect(params.length).toBe(4);

[queryText, params] = queries.getValueQuery;
expect(normalizeWhitespace(queryText as string)).toBe(`SELECT "tags" FROM "test_table" WHERE company_id = $1 AND id = $2`);
expect(params[0]).toBe(entity.company_id);
expect(params[1]).toBe(entity.id);
expect(params.length).toBe(2);
});

const assertInsertQueryParams = (actual: TestDbEntity, expected: any[]) => {
Expand Down

0 comments on commit 5320ad6

Please sign in to comment.