-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathprovider-visibility-issue.spec.ts
59 lines (52 loc) · 2.01 KB
/
provider-visibility-issue.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { expect, test } from '@jest/globals';
import { http, HttpKernel, HttpRequest } from '@deepkit/http';
import { App, createModule } from '@deepkit/app';
import { FrameworkModule } from '../../src/module.js';
import { SessionForRequest } from './session-for-request.dto.js';
import { AuthenticationModule } from './auth-module.js';
test('provider-visibility-issue', async () => {
class IAMModule extends createModule({ exports: [AuthenticationModule] }) {
imports = [new AuthenticationModule()];
}
@http.controller('/another')
class AnotherDomainModuleController {
@http.GET('/action')
action(sess: SessionForRequest) {
// Trying to consume "SessionForRequest" within another module – still no luck
return sess;
}
}
class AnotherDomainModule extends createModule({}) {
controllers = [AnotherDomainModuleController];
}
class DomainModule extends createModule({ exports: [IAMModule] }) {
imports = [new IAMModule(), new AnotherDomainModule()];
}
class InfrastructureModule extends createModule({
// The whole issue gets "fixed" if DomainModule gets exported here, but what if I don't need to export it?
exports: [],
}) {
imports = [new DomainModule()];
}
const app = new App({
imports: [
new FrameworkModule({ debug: true }),
new InfrastructureModule(),
],
providers: [],
});
/**
* These fail due to the following error:
*
* Controller for route /auth/whoami parameter resolving error:
* DependenciesUnmetError: Parameter sess is required but provider returned undefined.
*/
expect((await app.get(HttpKernel).request(HttpRequest.GET('/auth/whoami'))).json).toMatchObject({
sessionId: 'sidValue',
userId: 'uidValue'
});
expect((await app.get(HttpKernel).request(HttpRequest.GET('/another/action'))).json).toMatchObject({
sessionId: 'sidValue',
userId: 'uidValue'
});
});