-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supply space id to tutorial context (#22760)
- Loading branch information
Showing
4 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/spaces/server/lib/spaces_tutorial_context_factory.test.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,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { DEFAULT_SPACE_ID } from '../../common/constants'; | ||
import { createSpacesService } from './create_spaces_service'; | ||
import { createSpacesTutorialContextFactory } from './spaces_tutorial_context_factory'; | ||
|
||
const server = { | ||
config: () => { | ||
return { | ||
get: (key: string) => { | ||
if (key === 'server.basePath') { | ||
return '/foo'; | ||
} | ||
throw new Error('unexpected key ' + key); | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
describe('createSpacesTutorialContextFactory', () => { | ||
it('should create a valid context factory', () => { | ||
const spacesService = createSpacesService(server); | ||
expect(typeof createSpacesTutorialContextFactory(spacesService)).toEqual('function'); | ||
}); | ||
|
||
it('should create context with the current space id for space my-space-id', () => { | ||
const spacesService = createSpacesService(server); | ||
const contextFactory = createSpacesTutorialContextFactory(spacesService); | ||
|
||
const request = { | ||
getBasePath: () => '/foo/s/my-space-id', | ||
}; | ||
|
||
expect(contextFactory(request)).toEqual({ | ||
spaceId: 'my-space-id', | ||
}); | ||
}); | ||
|
||
it('should create context with the current space id for the default space', () => { | ||
const spacesService = createSpacesService(server); | ||
const contextFactory = createSpacesTutorialContextFactory(spacesService); | ||
|
||
const request = { | ||
getBasePath: () => '/foo', | ||
}; | ||
|
||
expect(contextFactory(request)).toEqual({ | ||
spaceId: DEFAULT_SPACE_ID, | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/spaces/server/lib/spaces_tutorial_context_factory.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,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SpacesService } from './create_spaces_service'; | ||
|
||
export function createSpacesTutorialContextFactory(spacesService: SpacesService) { | ||
return function spacesTutorialContextFactory(request: any) { | ||
return { | ||
spaceId: spacesService.getSpaceId(request), | ||
}; | ||
}; | ||
} |