Skip to content

Commit

Permalink
ci: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loopingz committed Nov 18, 2023
1 parent e525412 commit 1bc2173
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/core/src/services/domainservice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,16 @@ class DomainServiceTest extends WebdaTest {
url: "/openapi"
});
assert.ok(result.includes('spec = {"openapi"'));
this.webda.getRouter().removeRoute("/openapi");
rest.getParameters().exposeOpenAPI = false;
await rest.resolve().init();
await assert.rejects(
() =>
this.http({
method: "GET",
url: "/openapi"
}),
/OpenAPI not available/
/route not found/
);
}
}
6 changes: 5 additions & 1 deletion packages/core/src/stores/memory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { suite, test } from "@testdeck/mocha";
import * as assert from "assert";
import { existsSync, unlinkSync } from "fs";
import sinon from "sinon";
import { AggregatorService, CoreModel, Ident, MemoryStore, Store, User, WebdaError } from "../index";
import { HttpContext } from "../utils/httpcontext";
import { JSONUtils } from "../utils/serializers";
import { StoreNotFoundError } from "./store";
import { PermissionModel, StoreTest } from "./store.spec";
import { WebdaQL } from "./webdaql/query";
import sinon from "sinon";

@suite
class MemoryStoreTest extends StoreTest {
Expand Down Expand Up @@ -252,6 +252,10 @@ class MemoryStoreTest extends StoreTest {
});
await usersStore.getMigration(`storeMigration.${usersStore.getName()}.typesShortId`);
await usersStore.cancelMigration(`storeMigration.${usersStore.getName()}.typesShortId`);

await usersStore.migration("test", async () => {
return async () => {};
});
}

@test
Expand Down
24 changes: 24 additions & 0 deletions packages/postgres/src/postgresstore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { suite, test } from "@testdeck/mocha";
import { Ident, Store } from "@webda/core";
import { StoreTest } from "@webda/core/lib/stores/store.spec";
import * as assert from "assert";
import pg from "pg";
import PostgresStore from "./postgresstore";

@suite
Expand All @@ -22,6 +23,29 @@ export class PostgresTest extends StoreTest {
return super.deleteConcurrent();
}

@test
async createTable() {
const client = new pg.Client({
host: "localhost",
user: "webda.io",
database: "webda.io",
password: "webda.io"
});
try {
await client.connect();
await client.query("DROP TABLE IF EXISTS create_test");
let store: PostgresStore = this.getService<PostgresStore>("idents");
store.getParameters().table = "create_test";
store.getParameters().autoCreateTable = true;
await store.init();
await store.save({ test: 1 });
const res = await store.getClient().query("SELECT * FROM create_test");
assert.strictEqual(res.rowCount, 1);
} finally {
await client.end();
}
}

@test
async cov() {
let store: PostgresStore = this.getService<PostgresStore>("idents");
Expand Down
4 changes: 2 additions & 2 deletions packages/postgres/src/postgresstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class PostgresStore<
if (!this.parameters.autoCreateTable) {
return;
}
await this.sqlQuery(
await this.client.query(
`CREATE TABLE IF NOT EXISTS ${this.parameters.table} (uuid VARCHAR(255) NOT NULL, data jsonb, CONSTRAINT ${this.parameters.table}_pkey PRIMARY KEY (uuid))`
);
}
Expand All @@ -87,7 +87,7 @@ export default class PostgresStore<
* @param query
* @returns
*/
async executeQuery(query: string, values: any[]): Promise<SQLResult<T>> {
async executeQuery(query: string, values: any[] = []): Promise<SQLResult<T>> {
this.log("DEBUG", "Query", query);
let res = await this.client.query(query, values);
return {
Expand Down
3 changes: 2 additions & 1 deletion packages/postgres/test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"user": "webda.io",
"database": "webda.io",
"password": "webda.io",
"statement_timeout": 60000
"statement_timeout": 60000,
"max": 2
},
"usePool": true,
"sessionSecret": "Lp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5ENLp4B72FPU5n6q4EpVRGyPFnZp5cgLRPScVWixW52Yq84hD4MmnfVfgxKQ5EN"
Expand Down

0 comments on commit 1bc2173

Please sign in to comment.