Skip to content

Commit

Permalink
Merge pull request #1189 from Microsoft/jwilaby/azure-services
Browse files Browse the repository at this point in the history
Jwilaby/azure services
  • Loading branch information
Justin Wilaby committed Dec 19, 2018
2 parents abacaa7 + 213651f commit 3e3d9e7
Show file tree
Hide file tree
Showing 17 changed files with 860 additions and 271 deletions.
32 changes: 32 additions & 0 deletions packages/app/client/src/data/sagas/azureAuthSaga.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Bot Framework: http://botframework.com
//
// Bot Framework Emulator Github:
// https://github.com/Microsoft/BotFramwork-Emulator
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import { call, ForkEffect, put, select, takeEvery } from 'redux-saga/effects';
import {
AZURE_BEGIN_AUTH_WORKFLOW,
Expand Down
9 changes: 5 additions & 4 deletions packages/app/client/src/data/sagas/servicesExplorerSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ const getSortSelection = (state: RootState): { [paneldId: string]: SortCriteria

function* launchConnectedServicePicker(action: ConnectedServiceAction<ConnectedServicePickerPayload>)
: IterableIterator<any> {
// To retrieve the luis models, we must have the authoring key.
// To get the authoring key, we need the arm token
// To retrieve azure services, luis models and KBs,
// we must have the authoring key.
// To get the authoring key, we need the arm token.
let armTokenData: ArmTokenData & number = yield select(getArmTokenFromState);
if (!armTokenData || !armTokenData.access_token) {
const { promptDialog, loginSuccessDialog, loginFailedDialog } = action.payload.azureAuthWorkflowComponents;
Expand All @@ -86,6 +87,7 @@ function* launchConnectedServicePicker(action: ConnectedServiceAction<ConnectedS
));
}

// 2 means the user has chosen to manually enter the connected service
if (armTokenData === 2) {
yield* launchConnectedServiceEditor(action);
return;
Expand Down Expand Up @@ -165,7 +167,7 @@ function* retrieveServicesByServiceType(serviceType: ServiceTypes): IterableIter
let payload: ServicesPayload;
try {
payload = yield CommandServiceImpl.remoteCall(GetConnectedServicesByType, armTokenData.access_token, serviceType);
} catch {
} catch (e) {
payload = { services: [], code: ServiceCodes.Error };
}
return payload;
Expand Down Expand Up @@ -246,7 +248,6 @@ function* openAddConnectedServiceContextMenu(action: ConnectedServiceAction<Conn
const { id: serviceType } = response;
action.payload.serviceType = serviceType;
if (serviceType === ServiceTypes.Generic ||
serviceType === ServiceTypes.BlobStorage ||
serviceType === ServiceTypes.CosmosDB ||
serviceType === ServiceTypes.AppInsights) {
yield* launchConnectedServiceEditor(action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ServiceTypes } from 'botframework-config/lib/schema';
import { mount } from 'enzyme';
import * as React from 'react';
import { Provider } from 'react-redux';
import { mount } from 'enzyme';
import { GetStartedWithCSDialogContainer } from './getStartedWithCSDialogContainer';
import { combineReducers, createStore } from 'redux';
import { azureArmTokenDataChanged } from '../../../data/action/azureAuthActions';
import { azureAuth } from '../../../data/reducer/azureAuthReducer';
import { GetStartedWithCSDialog } from './getStartedWithCSDialog';
import { azureArmTokenDataChanged } from '../../../data/action/azureAuthActions';
import { ServiceTypes } from 'botframework-config/lib/schema';
import { GetStartedWithCSDialogContainer } from './getStartedWithCSDialogContainer';

jest.mock('../service', () => ({
DialogService: {
Expand All @@ -27,55 +27,84 @@ jest.mock('../../dialogs/', () => ({

describe('The GetStartedWithCSDialog component should', () => {
let mockStore;
let parent;
const mockArmToken = 'bm90aGluZw==.eyJ1cG4iOiJnbGFzZ293QHNjb3RsYW5kLmNvbSJ9.7gjdshgfdsk98458205jfds9843fjds';
beforeEach(() => {
mockStore = createStore(combineReducers({ azureAuth }));
mockStore.dispatch(azureArmTokenDataChanged(mockArmToken));
parent = mount(
<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Luis } />
</Provider>
);
});

it('should render deeply', () => {
const parent = mount(
<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Luis }/>
</Provider>
);
expect(parent.find(GetStartedWithCSDialogContainer)).not.toBe(null);
});

it('should contain both a cancel and confirm function in the props', () => {
const parent = mount(
<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Luis }/>
</Provider>
);
const prompt = parent.find(GetStartedWithCSDialog);
expect(typeof (prompt.props() as any).cancel).toBe('function');
expect(typeof (prompt.props() as any).confirm).toBe('function');
expect(typeof (prompt.props() as any).launchConnectedServiceEditor).toBe('function');
});

it('should display luisNoModelsFoundContent when the ServiceTypes.Luis and ' +
'showNoModelsFoundContent is provided in the props', () => {
const parent: any = mount(
<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer showNoModelsFoundContent={ true } serviceType={ ServiceTypes.Luis }/>
</Provider>
);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.luisNoModelsFoundContent);
});

it('should display luisContent when the ServiceTypes.Luis is provided in the props', () => {
const parent: any = mount(
<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Luis }/>
</Provider>
);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.luisContent);
});

it('should display luisContent when the ServiceTypes.Dispatch is provided in the props', () => {
parent = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Dispatch } />
it('should display dispatchContent when the ServiceTypes.Dispatch is provided in the props', () => {
const parent: any = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.Dispatch }/>
</Provider>);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.luisContent);
expect(prompt.content).toBe(prompt.dispatchContent);
});

it('should display dispatchNoModelsFoundContent when the ServiceTypes.Dispatch and ' +
'showNoModelsFoundContent is provided in the props', () => {
const parent: any = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer showNoModelsFoundContent={ true } serviceType={ ServiceTypes.Dispatch }/>
</Provider>);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.dispatchNoModelsFoundContent);
});

it('should display qnaContent when the ServiceTypes.QnA is provided in the props', () => {
parent = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.QnA } />
const parent: any = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.QnA }/>
</Provider>);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.qnaContent);
});

it('should display the "showNoModelsFoundContent" when specified in the props', () => {
parent = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.QnA } showNoModelsFoundContent={ true } />
it('should display blobContent when the ServiceTypes.BlobStorage is provided in the props', () => {
const parent: any = mount(<Provider store={ mockStore }>
<GetStartedWithCSDialogContainer serviceType={ ServiceTypes.BlobStorage }/>
</Provider>);
const prompt = parent.find(GetStartedWithCSDialog);
expect(prompt.content).toBe(prompt.qnaContent);
expect(prompt.content).toBe(prompt.blobContent);
});
});
Loading

0 comments on commit 3e3d9e7

Please sign in to comment.