forked from microsoft/BotFramework-Composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ability to view storages when in local dev on mac (microsoft#1696)
* change path param to query param * enable tests to import from '@src' * don't typecheck before tests * add test for storage controller * fix unhandled rejection warning * update client's jest config to allow importing from @src * pass path as query string when fetching storage folders * add working directory for vscode eslint integration * add missing copyright headers
- Loading branch information
1 parent
9b4831f
commit 730433c
Showing
19 changed files
with
261 additions
and
46 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
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,12 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { ActionTypes } from '@src/constants'; | ||
|
||
declare global { | ||
namespace jest { | ||
interface Matchers<R> { | ||
toBeDispatchedWith(type: ActionTypes, payload?: any, error?: any); | ||
} | ||
} | ||
} |
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,41 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import formatMessage from 'format-message'; | ||
import { setIconOptions } from 'office-ui-fabric-react/lib/Styling'; | ||
import 'jest-dom/extend-expect'; | ||
import { cleanup } from 'react-testing-library'; | ||
|
||
// Suppress icon warnings. | ||
setIconOptions({ | ||
disableWarnings: true, | ||
}); | ||
|
||
formatMessage.setup({ | ||
missingTranslation: 'ignore', | ||
}); | ||
|
||
expect.extend({ | ||
toBeDispatchedWith(dispatch: jest.Mock, type: string, payload: any, error?: any) { | ||
if (this.isNot) { | ||
expect(dispatch).not.toHaveBeenCalledWith({ | ||
type, | ||
payload, | ||
error, | ||
}); | ||
} else { | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type, | ||
payload, | ||
error, | ||
}); | ||
} | ||
|
||
return { | ||
pass: !this.isNot, | ||
message: () => 'dispatch called with correct type and payload', | ||
}; | ||
}, | ||
}); | ||
|
||
afterEach(cleanup); |
64 changes: 64 additions & 0 deletions
64
Composer/packages/client/__tests__/store/actions/storage.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,64 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import httpClient from '@src/utils/httpUtil'; | ||
import { ActionTypes } from '@src/constants'; | ||
import { fetchFolderItemsByPath } from '@src/store/action/storage'; | ||
import { Store } from '@src/store/types'; | ||
|
||
jest.mock('@src/utils/httpUtil'); | ||
|
||
const dispatch = jest.fn(); | ||
|
||
const store = ({ dispatch, getState: () => ({}) } as unknown) as Store; | ||
|
||
describe('fetchFolderItemsByPath', () => { | ||
const id = 'default'; | ||
const path = '/some/path'; | ||
|
||
it('dispatches SET_STORAGEFILE_FETCHING_STATUS', async () => { | ||
await fetchFolderItemsByPath(store, id, path); | ||
|
||
expect(dispatch).toBeDispatchedWith(ActionTypes.SET_STORAGEFILE_FETCHING_STATUS, { | ||
status: 'pending', | ||
}); | ||
}); | ||
|
||
it('fetches folder items from api', async () => { | ||
await fetchFolderItemsByPath(store, id, path); | ||
|
||
expect(httpClient.get).toHaveBeenCalledWith(`/storages/${id}/blobs`, { params: { path } }); | ||
}); | ||
|
||
describe('when api call is successful', () => { | ||
beforeEach(() => { | ||
(httpClient.get as jest.Mock).mockResolvedValue({ some: 'response' }); | ||
}); | ||
|
||
it('dispatches GET_STORAGEFILE_SUCCESS', async () => { | ||
await fetchFolderItemsByPath(store, id, path); | ||
|
||
expect(dispatch).toBeDispatchedWith(ActionTypes.GET_STORAGEFILE_SUCCESS, { | ||
response: { some: 'response' }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when api call fails', () => { | ||
beforeEach(() => { | ||
(httpClient.get as jest.Mock).mockRejectedValue('some error'); | ||
}); | ||
|
||
it('dispatches SET_STORAGEFILE_FETCHING_STATUS', async () => { | ||
await fetchFolderItemsByPath(store, id, path); | ||
|
||
expect(dispatch).toBeDispatchedWith( | ||
ActionTypes.SET_STORAGEFILE_FETCHING_STATUS, | ||
{ | ||
status: 'failure', | ||
}, | ||
'some 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
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,14 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/// <reference types="jest" /> | ||
|
||
const defaultResponse = { data: {} }; | ||
|
||
export default { | ||
get: jest.fn().mockResolvedValue(defaultResponse), | ||
post: jest.fn().mockResolvedValue(defaultResponse), | ||
put: jest.fn().mockResolvedValue(defaultResponse), | ||
patch: jest.fn().mockResolvedValue(defaultResponse), | ||
delete: jest.fn().mockResolvedValue(defaultResponse), | ||
}; |
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,13 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "build", | ||
"allowJs": true, | ||
"declaration": false, | ||
"module": "esnext", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@app/*": ["src/*"] | ||
"@src/*": ["src/*"] | ||
} | ||
}, | ||
"include": ["./src/**/*", "./__tests__/**/*"], | ||
"include": ["./src/**/*", "./__tests__/**/*"] | ||
} |
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
56 changes: 56 additions & 0 deletions
56
Composer/packages/server/__tests__/controllers/storage.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,56 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { Request, Response } from 'express'; | ||
import StorageService from '@src/services/storage'; | ||
import { StorageController } from '@src/controllers/storage'; | ||
|
||
jest.mock('@src/services/storage', () => ({ | ||
getBlob: jest.fn(), | ||
})); | ||
|
||
let mockReq: Request; | ||
let mockRes: Response; | ||
|
||
beforeEach(() => { | ||
mockReq = { | ||
params: {}, | ||
query: {}, | ||
body: {}, | ||
} as Request; | ||
|
||
mockRes = { | ||
status: jest.fn().mockReturnThis(), | ||
json: jest.fn().mockReturnThis(), | ||
} as any; | ||
}); | ||
|
||
describe('getBlob', () => { | ||
beforeEach(() => { | ||
mockReq.params.storageId = 'default'; | ||
}); | ||
|
||
it('returns 400 when path query not present', async () => { | ||
await StorageController.getBlob(mockReq, mockRes); | ||
|
||
expect(mockRes.status).toHaveBeenCalledWith(400); | ||
expect(mockRes.json).toHaveBeenCalledWith({ message: 'path missing from query' }); | ||
}); | ||
|
||
it('returns 400 when path is not absolute', async () => { | ||
mockReq.query.path = 'some/path'; | ||
await StorageController.getBlob(mockReq, mockRes); | ||
|
||
expect(mockRes.status).toHaveBeenCalledWith(400); | ||
expect(mockRes.json).toHaveBeenCalledWith({ message: 'path must be absolute' }); | ||
}); | ||
|
||
it('returns blob for absolute path', async () => { | ||
mockReq.query.path = '/some/path'; | ||
(StorageService.getBlob as jest.Mock).mockResolvedValue('some blob'); | ||
await StorageController.getBlob(mockReq, mockRes); | ||
|
||
expect(mockRes.status).toHaveBeenCalledWith(200); | ||
expect(mockRes.json).toHaveBeenCalledWith('some blob'); | ||
}); | ||
}); |
Oops, something went wrong.