Browse Source

chore/minor fix

pull/3358/head
Muhammed Mustafa 2 years ago
parent
commit
843ec4d3eb
  1. 2
      packages/nocodb/src/lib/Noco.ts
  2. 5
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  3. 36
      packages/nocodb/tests/unit/TestDbMngr.ts
  4. 7
      packages/nocodb/tests/unit/factory/project.ts

2
packages/nocodb/src/lib/Noco.ts

@ -81,12 +81,10 @@ export default class Noco {
return Noco._this.router;
}
Noco._this = new Noco();
Noco.initialized = true;
return Noco._this.init(args, server, app);
}
private static config: NcConfig;
public static initialized: boolean;
public readonly router: express.Router;
public readonly projectRouter: express.Router;
public static _ncMeta: NcMetaIO;

5
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -1786,7 +1786,7 @@ class BaseModelSqlv2 {
queryResponse = (await qb) as any;
}
const count = queryResponse.count || queryResponse;
const count = queryResponse ?? 0;
await this.afterBulkUpdate(count, this.dbDriver, cookie);
return count;
@ -1853,9 +1853,8 @@ class BaseModelSqlv2 {
this.dbDriver
);
qb.del();
const queryResponse = (await qb) as any;
const count = (await qb) as any;
const count = queryResponse.count || queryResponse;
await this.afterBulkDelete(count, this.dbDriver, cookie);
return count;

36
packages/nocodb/tests/unit/TestDbMngr.ts

@ -30,33 +30,16 @@ export default class TestDbMngr {
}
}
static async init({
user = TestDbMngr.defaultConnection.user,
password = TestDbMngr.defaultConnection.password,
host = TestDbMngr.defaultConnection.host,
port = TestDbMngr.defaultConnection.port,
client = TestDbMngr.defaultConnection.client,
} = {}) {
if(await TestDbMngr.isMysqlConfigured({ user, password, host, port, client })){
await TestDbMngr.connectMysql({ user, password, host, port, client });
static async init() {
if(await TestDbMngr.isMysqlConfigured()){
await TestDbMngr.connectMysql();
} else {
await TestDbMngr.switchToSqlite();
}
}
static async isMysqlConfigured({
user,
password,
host,
port,
client,
}: {
user: string,
password: string,
host: string,
port: number,
client: string,
}) {
static async isMysqlConfigured() {
const { user, password, host, port, client } = TestDbMngr.defaultConnection;
const config = NcConfigFactory.urlToDbConfig(`${client}://${user}:${password}@${host}:${port}`);
config.connection = {
user,
@ -68,13 +51,8 @@ export default class TestDbMngr {
return result.code !== -1;
}
static async connectMysql({
user = TestDbMngr.defaultConnection.user,
password = TestDbMngr.defaultConnection.password,
host = TestDbMngr.defaultConnection.host,
port = TestDbMngr.defaultConnection.port,
client = TestDbMngr.defaultConnection.client,
}) {
static async connectMysql() {
const { user, password, host, port, client } = TestDbMngr.defaultConnection;
if(!process.env[`DATABASE_URL`]){
process.env[`DATABASE_URL`] = `${client}://${user}:${password}@${host}:${port}/${TestDbMngr.dbName}`;
}

7
packages/nocodb/tests/unit/factory/project.ts

@ -49,9 +49,7 @@ const createSakilaProject = async (context) => {
.set('xc-auth', context.token)
.send(externalProjectConfig);
const project: Project = await Project.getByTitleOrId(response.body.id);
return project;
return (await Project.getByTitleOrId(response.body.id)) as Project;
};
const createProject = async (context, projectArgs = defaultProjectValue) => {
@ -60,8 +58,7 @@ const createProject = async (context, projectArgs = defaultProjectValue) => {
.set('xc-auth', context.token)
.send(projectArgs);
const project: Project = await Project.getByTitleOrId(response.body.id);
return project;
return (await Project.getByTitleOrId(response.body.id)) as Project;
};
export { createProject, createSharedBase, createSakilaProject };

Loading…
Cancel
Save