Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { absHostedConfig } from '../../../src/models/environment';
import { HostedEnvironment } from '../../../src/models/environment/hostedEnvironment';
import { Path } from '../../../src/utility/path';

const dir = './mocks';
const defaultDir = Path.join(__dirname, dir);

describe('getEnvironmentName', () => {
it('return projectName', async () => {
const e = new HostedEnvironment({ ...absHostedConfig, basePath: defaultDir }, true);
const result = e.getEnvironmentName('foo');
expect(result).toBe('foo');
});
});

describe('slots', () => {
it('getDefaultSlot', async () => {
const e = new HostedEnvironment({ ...absHostedConfig, basePath: defaultDir }, true);
const result = e.getDefaultSlot();
expect(result).toBe('integration');
});

it('getSlotNames', async () => {
const e = new HostedEnvironment({ ...absHostedConfig, basePath: defaultDir }, true);
const result = e.getSlotNames();
expect(result.length).toBe(2);
expect(result[0]).toBe('integration');
expect(result[1]).toBe('production');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FileSettingManager } from '../../../src/models/settings/fileSettingManager';
import { Path } from '../../../src/utility/path';

const dir = './mocks';
const defaultDir = Path.join(__dirname, dir);

describe('get', () => {
it('return values', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('', false);
expect(result.label).toBe('default');
});

it('return obfuscated alues', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('', true);
expect(result.label).toBe('*****');
expect(result.mock1).toBe('*****');
expect(result.mock2).toBe('*****');
expect(result.mock3.mock3).toBe('*****');
expect(result.mock3.mock4).toBe('*****');
expect(result.mock3.mock5[0]).toBe('*****');
expect(result.mock3.mock5[1]).toBe('*****');
});

it('return slot values', async () => {
const sm = new FileSettingManager(defaultDir);
const result = await sm.get('integration', false);
expect(result.label).toBe('integration');
const result2 = await sm.get('production', false);
expect(result2.label).toBe('production');
const result3 = await sm.get('bonus', false);
expect(result3.label).toBe('bonus');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { HostedSettingManager } from '../../../src/models/settings/hostedSettingManager';
import { Path } from '../../../src/utility/path';

const dir = './mocks';
const defaultDir = Path.join(__dirname, dir);

describe('get', () => {
it('throws with invalid slot name', async () => {
const sm = new HostedSettingManager(defaultDir);
let threw = false;
try {
await sm.get('bad', true);
} catch (x) {
threw = true;
}

expect(threw).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"label": "bonus",
"mock1": 123,
"mock2": "abc",
"mock3": {
"mock3": 456,
"mock4": "xyz",
"mock5": [
789,
"pnm"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"label": "integration",
"mock1": 123,
"mock2": "abc",
"mock3": {
"mock3": 456,
"mock4": "xyz",
"mock5": [
789,
"pnm"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"label": "production",
"mock1": 123,
"mock2": "abc",
"mock3": {
"mock3": 456,
"mock4": "xyz",
"mock5": [
789,
"pnm"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"label": "default",
"mock1": 123,
"mock2": "abc",
"mock3": {
"mock3": 456,
"mock4": "xyz",
"mock5": [
789,
"pnm"
]
}
}
15 changes: 8 additions & 7 deletions Composer/packages/server/__tests__/services/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import rimraf from 'rimraf';

import { Path } from '../../src/utility/path';
import { BotProject } from '../../src/models/bot/botProject';
import projectService from '../../src/services/project';
import { BotProjectService } from '../../src/services/project';

// offer a bot project ref which to open
jest.mock('../../src/store/store', () => {
const data = {
Expand Down Expand Up @@ -36,23 +37,23 @@ const saveAsDir = Path.resolve(__dirname, '../mocks/samplebots/saveas');

describe('test BotProjectService', () => {
it('openProject', async () => {
expect(projectService.currentBotProject).toBeUndefined();
expect(BotProjectService.getCurrentBotProject()).toBeUndefined();

const botProj = {
storageId: 'default',
path: projPath,
};
await projectService.openProject(botProj);
expect(projectService.currentBotProject).toBeDefined();
expect((projectService.currentBotProject as BotProject).dir).toBe(projPath);
await BotProjectService.openProject(botProj);
expect(BotProjectService.getCurrentBotProject()).toBeDefined();
expect((BotProjectService.getCurrentBotProject() as BotProject).dir).toBe(projPath);
});
it('saveProjectAs', async () => {
const botProj = {
storageId: 'default',
path: saveAsDir,
};
await projectService.saveProjectAs(botProj);
expect((projectService.currentBotProject as BotProject).dir).toBe(`${saveAsDir}`);
await BotProjectService.saveProjectAs(botProj);
expect((BotProjectService.getCurrentBotProject() as BotProject).dir).toBe(`${saveAsDir}`);
// remove the saveas files
try {
rimraf.sync(saveAsDir);
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/server/settings/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 7 additions & 4 deletions Composer/packages/server/src/controllers/connector.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BotEnvironments } from '../models/connector';
import BotConnectorService from '../services/connector';
import { EnvironmentProvider } from '../models/environment';

async function connect(req: any, res: any) {
try {
const hostName = req.hostname;
const env: BotEnvironments = req.query && req.query.botEnvironment ? req.query.botEnvironment : 'production';
const botEndpoint = await BotConnectorService.connect(env, hostName);
const environment = EnvironmentProvider.getCurrent();
const botEndpoint = await environment.getBotConnector().connect(env || 'production', hostName);
res.send({ botEndpoint });
} catch (error) {
res.status(400).json({
Expand All @@ -16,7 +17,8 @@ async function connect(req: any, res: any) {

async function sync(req: any, res: any) {
try {
await BotConnectorService.sync({ ...req.body, user: req.user });
const environment = EnvironmentProvider.getCurrent();
await environment.getBotConnector().sync({ ...req.body, user: req.user });
res.send('OK');
} catch (error) {
res.status(400).json({
Expand All @@ -26,7 +28,8 @@ async function sync(req: any, res: any) {
}

function status(req: any, res: any) {
res.send(BotConnectorService.status());
const environment = EnvironmentProvider.getCurrent();
res.send(environment.getBotConnector().status);
}

export const BotConnectorController = {
Expand Down
Loading