Skip to content

Commit 51e74a1

Browse files
Copilotnomeguy
andcommitted
Address code review feedback - refactor duplicated code and improve naming
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
1 parent 78d04aa commit 51e74a1

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/__test__/enforcer.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ test('Load casbin from strings.', async () => {
7878
expect(await e.enforce("alice", "data1", "write")).toBe(false);
7979
})
8080

81-
const respDataWithMultipleRoles = JSON.stringify({
81+
const rbacMultipleRolesRespData = JSON.stringify({
8282
m: rbacModelStr,
8383
p: [
8484
["p", "admin", "data1", "read"],
@@ -95,7 +95,7 @@ const respDataWithMultipleRoles = JSON.stringify({
9595

9696
test('Authorizer with multiple roles per user', async() => {
9797
const authorizer = new Authorizer("auto", {endpoint: "whatever"});
98-
await authorizer.initEnforcer(respDataWithMultipleRoles);
98+
await authorizer.initEnforcer(rbacMultipleRolesRespData);
9999

100100
// Test alice who has both admin and editor roles
101101
authorizer.user = "alice";

src/__test__/server.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ class TestServer {
9898
})
9999
}
100100

101-
public async start() : Promise<void> {
102-
await this.casbinServ.run();
103-
this.setRouter();
101+
private startServer(): Promise<void> {
104102
return new Promise((resolve) => {
105103
this.listener = this.app.listen(this.port, () => {
106104
console.log(`Express server is listening at http://localhost:${this.port}`);
@@ -109,15 +107,16 @@ class TestServer {
109107
});
110108
}
111109

110+
public async start() : Promise<void> {
111+
await this.casbinServ.run();
112+
this.setRouter();
113+
return this.startServer();
114+
}
115+
112116
public async startWithRBAC() : Promise<void> {
113117
await this.casbinServ.runWithRBAC();
114118
this.setRouter();
115-
return new Promise((resolve) => {
116-
this.listener = this.app.listen(this.port, () => {
117-
console.log(`Express server is listening at http://localhost:${this.port}`);
118-
resolve();
119-
});
120-
});
119+
return this.startServer();
121120
}
122121

123122
public terminate() : void {

0 commit comments

Comments
 (0)