-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from atlassian/ARC-2494-redirect-from-get-sta…
…rted Arc-2494 redirect from get started
- Loading branch information
Showing
10 changed files
with
201 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export const invoke = jest.fn(); | ||
export const router = { | ||
navigate: jest.fn() | ||
}; |
46 changes: 46 additions & 0 deletions
46
app/jenkins-for-jira-ui/src/api/redirectFromGetStarted.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,46 @@ | ||
import { invoke, router } from '@forge/bridge'; | ||
import { redirectFromGetStarted } from './redirectFromGetStarted'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('redirectFromGetStarted', () => { | ||
it('should call invoke and router.navigate with the correct parameters from get started page', async () => { | ||
const contextData = { | ||
siteUrl: 'https://testjirasite.com', | ||
appId: '1234-567-890', | ||
environmentId: '93-2348248121-3428-345734593', | ||
moduleKey: 'get-started-page' | ||
}; | ||
|
||
(invoke as jest.Mock).mockResolvedValue(contextData); | ||
await redirectFromGetStarted(); | ||
expect(invoke).toHaveBeenCalledWith('redirectFromGetStarted'); | ||
expect(router.navigate).toHaveBeenCalledWith( | ||
`${contextData.siteUrl}/jira/settings/apps/${contextData.appId}/${contextData.environmentId}/` | ||
); | ||
}); | ||
|
||
it('should call invoke but should not call router.navigate with the correct parameters from admin page', | ||
async () => { | ||
const contextData = { | ||
siteUrl: 'https://testjirasite.com', | ||
appId: '1234-567-890', | ||
environmentId: '93-2348248121-3428-345734593', | ||
moduleKey: 'not-get-started-page' | ||
}; | ||
|
||
(invoke as jest.Mock).mockResolvedValue(contextData); | ||
await redirectFromGetStarted(); | ||
expect(invoke).toHaveBeenCalledWith('redirectFromGetStarted'); | ||
expect(router.navigate).not.toHaveBeenCalledWith( | ||
`${contextData.siteUrl}/jira/settings/apps/${contextData.appId}/${contextData.environmentId}/` | ||
); | ||
}); | ||
|
||
it('should handle errors gracefully', async () => { | ||
(invoke as jest.Mock).mockRejectedValue(new Error('Test error')); | ||
await expect(redirectFromGetStarted()).rejects.toThrow('Test error'); | ||
}); | ||
}); |
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,28 @@ | ||
import { invoke, router } from '@forge/bridge'; | ||
|
||
interface Context { | ||
siteUrl: string; | ||
appId: string; | ||
environmentId: string; | ||
moduleKey: string; | ||
} | ||
|
||
const redirectFromGetStarted = async (): Promise<string> => { | ||
const context: Context = await invoke('redirectFromGetStarted'); | ||
const { | ||
siteUrl, | ||
appId, | ||
environmentId, | ||
moduleKey | ||
} = context; | ||
|
||
if (moduleKey === 'get-started-page') { | ||
router.navigate(`${siteUrl}/jira/settings/apps/${appId}/${environmentId}/`); | ||
} | ||
|
||
return moduleKey; | ||
}; | ||
|
||
export { | ||
redirectFromGetStarted | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import resolver from './resolvers'; | ||
import { redirectFromGetStarted } from './utils/redirect-from-get-started'; | ||
import handleJenkinsRequest from './webtrigger/handle-jenkins-request'; | ||
import { handleResetJenkinsRequest } from './webtrigger/handle-reset-jenkins-request'; | ||
|
||
// webtriggers | ||
export { handleJenkinsRequest, handleResetJenkinsRequest }; | ||
|
||
// resolvers | ||
export { resolver }; | ||
export { resolver, redirectFromGetStarted }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { redirectFromGetStarted, RedirectFromGetStarted } from './redirect-from-get-started'; | ||
|
||
describe('redirectFromGetStarted', () => { | ||
it('should return the expected RedirectFromGetStarted object', () => { | ||
const mockRequest = { | ||
context: { | ||
siteUrl: 'https://testjira.com', | ||
appId: 'df76f661-4cbe-4768-a119-13992dc4ce2d', | ||
environmentId: '1831-1281423-12389342983', | ||
moduleKey: 'some-page' | ||
}, | ||
}; | ||
|
||
const result: RedirectFromGetStarted = redirectFromGetStarted(mockRequest); | ||
const { | ||
siteUrl, | ||
appId, | ||
environmentId, | ||
moduleKey | ||
} = mockRequest.context; | ||
const expected: RedirectFromGetStarted = { | ||
siteUrl, | ||
appId, | ||
environmentId, | ||
moduleKey | ||
}; | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
}); |
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,19 @@ | ||
export type RedirectFromGetStarted = { | ||
siteUrl: string, | ||
appId: string, | ||
environmentId: string, | ||
moduleKey: string | ||
}; | ||
|
||
const redirectFromGetStarted = (request: any): RedirectFromGetStarted => { | ||
const { siteUrl, environmentId, moduleKey } = request.context; | ||
const appId = 'df76f661-4cbe-4768-a119-13992dc4ce2d'; | ||
return { | ||
siteUrl, | ||
appId, | ||
environmentId, | ||
moduleKey | ||
}; | ||
}; | ||
|
||
export { redirectFromGetStarted }; |