11import { PMPortalContextService } from './pm-portal-context.service.js' ;
22import { KcpKubernetesService } from './services/kcp-k8s.service.js' ;
3- import { getDomainAndOrganization } from './utils/domain.js' ;
3+ import { getOrganization } from './utils/domain.js' ;
44import { Test , TestingModule } from '@nestjs/testing' ;
55import { Request } from 'express' ;
66import { mock } from 'jest-mock-extended' ;
7+ import process from 'node:process' ;
78
89jest . mock ( '@kubernetes/client-node' , ( ) => {
910 class KubeConfig {
@@ -23,22 +24,19 @@ jest.mock('@kubernetes/client-node', () => {
2324} ) ;
2425
2526jest . mock ( './utils/domain.js' , ( ) => ( {
26- getDomainAndOrganization : jest . fn ( ) ,
27+ getOrganization : jest . fn ( ) ,
2728} ) ) ;
2829
2930describe ( 'PMPortalContextService' , ( ) => {
3031 let service : PMPortalContextService ;
3132 let kcpKubernetesServiceMock : jest . Mocked < KcpKubernetesService > ;
32- const mockedGetDomainAndOrganization = jest . mocked ( getDomainAndOrganization ) ;
33+ const mockedGetDomainAndOrganization = jest . mocked ( getOrganization ) ;
3334 let mockRequest : any ;
3435
3536 beforeEach ( async ( ) => {
3637 kcpKubernetesServiceMock = mock ( ) ;
3738
38- mockedGetDomainAndOrganization . mockReturnValue ( {
39- baseDomain : 'example.com' ,
40- organization : 'test-org' ,
41- } ) ;
39+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
4240
4341 const module : TestingModule = await Test . createTestingModule ( {
4442 providers : [
@@ -87,10 +85,7 @@ describe('PMPortalContextService', () => {
8785 process . env . OTHER_ENV_VAR = 'should-be-ignored' ;
8886
8987 try {
90- mockedGetDomainAndOrganization . mockReturnValue ( {
91- baseDomain : 'example.com' ,
92- organization : 'test-org' ,
93- } ) ;
88+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
9489
9590 const result = await service . getContextValues ( mockRequest as Request ) ;
9691
@@ -110,10 +105,7 @@ describe('PMPortalContextService', () => {
110105 process . env . OPENMFP_PORTAL_CONTEXT_MULTIPLE_SNAKE_CASE_KEYS = 'value2' ;
111106
112107 try {
113- mockedGetDomainAndOrganization . mockReturnValue ( {
114- baseDomain : 'example.com' ,
115- organization : 'test-org' ,
116- } ) ;
108+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
117109
118110 const result = await service . getContextValues ( mockRequest as Request ) ;
119111
@@ -132,10 +124,7 @@ describe('PMPortalContextService', () => {
132124 'https://${org-subdomain}api.example.com/${org-name}/graphql' ;
133125
134126 try {
135- mockedGetDomainAndOrganization . mockReturnValue ( {
136- baseDomain : 'example.com' ,
137- organization : 'test-org' ,
138- } ) ;
127+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
139128
140129 mockRequest . hostname = 'subdomain.example.com' ;
141130
@@ -154,11 +143,8 @@ describe('PMPortalContextService', () => {
154143 'https://${org-subdomain}api.example.com/${org-name}/graphql' ;
155144
156145 try {
157- mockedGetDomainAndOrganization . mockReturnValue ( {
158- baseDomain : 'example.com' ,
159- organization : 'test-org' ,
160- } ) ;
161-
146+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
147+ process . env [ 'BASE_DOMAINS_DEFAULT' ] = 'example.com' ;
162148 mockRequest . hostname = 'example.com' ;
163149
164150 const result = await service . getContextValues ( mockRequest as Request ) ;
@@ -177,10 +163,7 @@ describe('PMPortalContextService', () => {
177163 process . env . OPENMFP_PORTAL_CONTEXT_VALID_KEY = 'valid-value' ;
178164
179165 try {
180- mockedGetDomainAndOrganization . mockReturnValue ( {
181- baseDomain : 'example.com' ,
182- organization : 'test-org' ,
183- } ) ;
166+ mockedGetDomainAndOrganization . mockReturnValue ( 'test-org' ) ;
184167
185168 const result = await service . getContextValues ( mockRequest as Request ) ;
186169
0 commit comments