mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
Add tests for UsersManager (#1149)
Context
HomeDBManager lacks of direct tests, which makes hard to make rework or refactorations.
Proposed solution
Specifically here, I introduce tests which call exposed UsersManager methods directly and check their result.
Also:
I removed updateUserName which seems to me useless (updateUser does the same work)
Taking a look at the getUserByLogin methods, it appears that Typescirpt infers it returns a Promise<User|null> while in no case it may resolve a nullish value, therefore I have forced to return a Promise<User> and have changed the call sites to reflect the change.
Related issues
I make this change for then working on #870
This commit is contained in:
@@ -122,7 +122,7 @@ describe('fixSiteProducts', function() {
|
||||
assert.equal(getDefaultProductNames().teamInitial, 'stub');
|
||||
|
||||
const db = server.dbManager;
|
||||
const user = await db.getUserByLogin(email, {profile}) as any;
|
||||
const user = await db.getUserByLogin(email, {profile});
|
||||
const orgId = db.unwrapQueryResult(await db.addOrg(user, {
|
||||
name: 'sanity-check-org',
|
||||
domain: 'sanity-check-org',
|
||||
|
||||
@@ -3279,7 +3279,7 @@ describe('GranularAccess', function() {
|
||||
cliOwner.flush();
|
||||
let perm: PermissionDataWithExtraUsers = (await cliOwner.send("getUsersForViewAs", 0)).data;
|
||||
const getId = (name: string) => home.dbManager.testGetId(name) as Promise<number>;
|
||||
const getRef = (email: string) => home.dbManager.getUserByLogin(email).then(user => user!.ref);
|
||||
const getRef = (email: string) => home.dbManager.getUserByLogin(email).then(user => user.ref);
|
||||
assert.deepEqual(perm.users, [
|
||||
{ id: await getId('Chimpy'), email: 'chimpy@getgrist.com', name: 'Chimpy',
|
||||
ref: await getRef('chimpy@getgrist.com'),
|
||||
|
||||
@@ -2,13 +2,13 @@ import path from "path";
|
||||
import * as testUtils from "test/server/testUtils";
|
||||
import {execFileSync} from "child_process";
|
||||
|
||||
export async function prepareDatabase(tempDirectory: string) {
|
||||
export async function prepareDatabase(tempDirectory: string, filename: string = 'landing.db') {
|
||||
// Let's create a sqlite db that we can share with servers that run in other processes, hence
|
||||
// not an in-memory db. Running seed.ts directly might not take in account the most recent value
|
||||
// for TYPEORM_DATABASE, because ormconfig.js may already have been loaded with a different
|
||||
// configuration (in-memory for instance). Spawning a process is one way to make sure that the
|
||||
// latest value prevail.
|
||||
process.env.TYPEORM_DATABASE = path.join(tempDirectory, 'landing.db');
|
||||
process.env.TYPEORM_DATABASE = path.join(tempDirectory, filename);
|
||||
const seed = await testUtils.getBuildFile('test/gen-server/seed.js');
|
||||
execFileSync('node', [seed, 'init'], {
|
||||
env: process.env,
|
||||
|
||||
Reference in New Issue
Block a user