-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): generate valid regex in guard also for wildcard routes (#2231
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/app/core/permissions/permission-guard/abstract-permission.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { TestBed } from "@angular/core/testing"; | ||
import { Router, Routes } from "@angular/router"; | ||
import { AbstractPermissionGuard } from "./abstract-permission.guard"; | ||
import { Injectable } from "@angular/core"; | ||
import { DynamicComponentConfig } from "../../config/dynamic-components/dynamic-component-config.interface"; | ||
|
||
@Injectable() | ||
class TestPermissionGuard extends AbstractPermissionGuard { | ||
constructor(router: Router) { | ||
super(router); | ||
} | ||
|
||
protected async canAccessRoute( | ||
routeData: DynamicComponentConfig, | ||
): Promise<boolean> { | ||
return routeData?.config; | ||
} | ||
} | ||
|
||
describe("EntityPermissionGuard", () => { | ||
let guard: TestPermissionGuard; | ||
|
||
let testRoutes: Routes; | ||
|
||
beforeEach(() => { | ||
testRoutes = [{ path: "**", data: { config: true } }]; | ||
|
||
TestBed.configureTestingModule({ | ||
providers: [ | ||
TestPermissionGuard, | ||
{ provide: Router, useValue: { config: testRoutes } }, | ||
], | ||
}); | ||
guard = TestBed.inject(TestPermissionGuard); | ||
}); | ||
|
||
it("should be created", () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
|
||
it("should get route config also for '**' path", async () => { | ||
const result = await guard.checkRoutePermissions("url"); | ||
|
||
expect(result).toBeTrue(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters