Skip to content

Commit

Permalink
chore(NA): merge and solve conflicts with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic committed Feb 3, 2021
2 parents 94925da + 128d84f commit 1c4eb55
Show file tree
Hide file tree
Showing 13 changed files with 519 additions and 307 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@
"@types/mime": "^2.0.1",
"@types/mime-types": "^2.1.0",
"@types/minimatch": "^2.0.29",
"@types/mocha": "^7.0.2",
"@types/mocha": "^8.2.0",
"@types/mock-fs": "^4.10.0",
"@types/moment-timezone": "^0.5.12",
"@types/mustache": "^0.8.31",
Expand Down Expand Up @@ -728,10 +728,10 @@
"micromatch": "3.1.10",
"minimist": "^1.2.5",
"mkdirp": "0.5.1",
"mocha": "^7.1.1",
"mocha-junit-reporter": "^1.23.1",
"mochawesome": "^4.1.0",
"mochawesome-merge": "^4.1.0",
"mocha": "^8.2.1",
"mocha-junit-reporter": "^2.0.0",
"mochawesome": "^6.2.1",
"mochawesome-merge": "^4.2.0",
"mock-fs": "^4.12.0",
"mock-http-server": "1.3.0",
"ms-chromium-edge-driver": "^0.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ describe('failure hooks', function () {
it('runs and prints expected output', () => {
const proc = spawnSync(process.execPath, [SCRIPT, '--config', FAILURE_HOOKS_CONFIG]);
const lines = stripAnsi(proc.stdout.toString('utf8')).split(/\r?\n/);
const linesCopy = [...lines];

const tests = [
{
flag: '$FAILING_BEFORE_HOOK$',
flag: '"before all" hook: $FAILING_BEFORE_HOOK$',
assert(lines) {
expect(lines.shift()).toMatch(/info\s+testHookFailure\s+\$FAILING_BEFORE_ERROR\$/);
expect(lines.shift()).toMatch(
Expand All @@ -30,15 +32,15 @@ describe('failure hooks', function () {
},
},
{
flag: '$FAILING_TEST$',
flag: '└-> $FAILING_TEST$',
assert(lines) {
expect(lines.shift()).toMatch(/global before each/);
expect(lines.shift()).toMatch(/info\s+testFailure\s+\$FAILING_TEST_ERROR\$/);
expect(lines.shift()).toMatch(/info\s+testFailureAfterDelay\s+\$FAILING_TEST_ERROR\$/);
},
},
{
flag: '$FAILING_AFTER_HOOK$',
flag: '"after all" hook: $FAILING_AFTER_HOOK$',
assert(lines) {
expect(lines.shift()).toMatch(/info\s+testHookFailure\s+\$FAILING_AFTER_ERROR\$/);
expect(lines.shift()).toMatch(
Expand All @@ -48,14 +50,19 @@ describe('failure hooks', function () {
},
];

while (lines.length && tests.length) {
const line = lines.shift();
if (line.includes(tests[0].flag)) {
const test = tests.shift();
test.assert(lines);
try {
while (lines.length && tests.length) {
const line = lines.shift();
if (line.includes(tests[0].flag)) {
const test = tests.shift();
test.assert(lines);
}
}
}

expect(tests).toHaveLength(0);
expect(tests).toHaveLength(0);
} catch (error) {
console.error('full log output', linesCopy.join('\n'));
throw error;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ it('only runs hooks of parents and tests in level1a', async () => {
"suite: ",
"suite: level 1",
"suite: level 1 level 1a",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1a\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1a\\"",
"test: level 1 level 1a test 1a",
]
`);
Expand All @@ -108,8 +108,8 @@ it('only runs hooks of parents and tests in level1b', async () => {
"suite: ",
"suite: level 1",
"suite: level 1 level 1b",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1b\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1b\\"",
"test: level 1 level 1b test 1b",
]
`);
Expand All @@ -127,12 +127,12 @@ it('only runs hooks of parents and tests in level1a and level1b', async () => {
"suite: ",
"suite: level 1",
"suite: level 1 level 1a",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1a\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1a\\"",
"test: level 1 level 1a test 1a",
"suite: level 1 level 1b",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1b\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1b\\"",
"test: level 1 level 1b test 1b",
]
`);
Expand All @@ -151,8 +151,8 @@ it('only runs level1a if including level1 and excluding level1b', async () => {
"suite: ",
"suite: level 1",
"suite: level 1 level 1a",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1a\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1a\\"",
"test: level 1 level 1a test 1a",
]
`);
Expand All @@ -171,8 +171,8 @@ it('only runs level1b if including level1 and excluding level1a', async () => {
"suite: ",
"suite: level 1",
"suite: level 1 level 1b",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: level 1 \\"before each\\" hook: level1BeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 1b\\"",
"hook: level 1 \\"before each\\" hook: level1BeforeEach for \\"test 1b\\"",
"test: level 1 level 1b test 1b",
]
`);
Expand All @@ -190,7 +190,7 @@ it('only runs level2 if excluding level1', async () => {
"suite: ",
"suite: level 2",
"suite: level 2 level 2a",
"hook: \\"before each\\" hook: rootBeforeEach",
"hook: \\"before each\\" hook: rootBeforeEach for \\"test 2a\\"",
"test: level 2 level 2a test 2a",
]
`);
Expand Down
1 change: 0 additions & 1 deletion src/dev/build/tasks/clean_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const CleanExtraFilesFromModules: Task = {
'**/test',
'**/tests',
'**/__tests__',
'**/mocha.opts',
'**/*.test.js',
'**/*.snap',
'**/coverage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ export const GITHUB_LINK_TITLE = i18n.translate(

export const CUSTOM_SERVICE_TYPE = 'custom';

export const WORKPLACE_SEARCH_URL_PREFIX = '/app/enterprise_search/workplace_search';

export const DOCUMENTATION_LINK_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.sources.documentation',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../../../__mocks__';
import {
LogicMounter,
mockFlashMessageHelpers,
mockHttpValues,
mockKibanaValues,
} from '../../../../../__mocks__';

import { AppLogic } from '../../../../app_logic';
jest.mock('../../../../app_logic', () => ({
AppLogic: { values: { isOrganization: true } },
}));

import { SourcesLogic } from '../../sources_logic';

import { nextTick } from '@kbn/test/jest';

import { CustomSource } from '../../../../types';
import { SOURCES_PATH, getSourcesPath } from '../../../../routes';

import { sourceConfigData } from '../../../../__mocks__/content_sources.mock';

Expand All @@ -28,6 +36,7 @@ import {
describe('AddSourceLogic', () => {
const { mount } = new LogicMounter(AddSourceLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { clearFlashMessages, flashAPIErrors } = mockFlashMessageHelpers;

const defaultValues = {
Expand Down Expand Up @@ -264,6 +273,55 @@ describe('AddSourceLogic', () => {
});
});

describe('saveSourceParams', () => {
const params = {
code: 'code123',
state: '"{"state": "foo"}"',
session_state: 'session123',
};

const queryString =
'code=code123&state=%22%7B%22state%22%3A%20%22foo%22%7D%22&session_state=session123';

const response = { serviceName: 'name', indexPermissions: false, serviceType: 'zendesk' };

beforeEach(() => {
SourcesLogic.mount();
});

it('sends params to server and calls correct methods', async () => {
const setAddedSourceSpy = jest.spyOn(SourcesLogic.actions, 'setAddedSource');
const { serviceName, indexPermissions, serviceType } = response;
http.get.mockReturnValue(Promise.resolve(response));
AddSourceLogic.actions.saveSourceParams(queryString);
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/sources/create', {
query: {
...params,
kibana_host: '',
},
});

await nextTick();

expect(setAddedSourceSpy).toHaveBeenCalledWith(serviceName, indexPermissions, serviceType);
expect(navigateToUrl).toHaveBeenCalledWith(
getSourcesPath(SOURCES_PATH, AppLogic.values.isOrganization)
);
});

it('handles error', async () => {
http.get.mockReturnValue(Promise.reject('this is an error'));

AddSourceLogic.actions.saveSourceParams(queryString);
await nextTick();

expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
expect(navigateToUrl).toHaveBeenCalledWith(
getSourcesPath(SOURCES_PATH, AppLogic.values.isOrganization)
);
});
});

describe('organization context', () => {
describe('getSourceConfigData', () => {
it('calls API and sets values', async () => {
Expand Down Expand Up @@ -301,22 +359,37 @@ describe('AddSourceLogic', () => {

AddSourceLogic.actions.getSourceConnectData('github', successCallback);

const query = {
index_permissions: false,
kibana_host: '',
};

expect(clearFlashMessages).toHaveBeenCalled();
expect(AddSourceLogic.values.buttonLoading).toEqual(true);
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/org/sources/github/prepare');
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/sources/github/prepare',
{ query }
);
await nextTick();
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
expect(successCallback).toHaveBeenCalledWith(sourceConnectData.oauthUrl);
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
});

it('appends query params', () => {
it('passes query params', () => {
AddSourceLogic.actions.setSourceSubdomainValue('subdomain');
AddSourceLogic.actions.setSourceIndexPermissionsValue(true);
AddSourceLogic.actions.getSourceConnectData('github', successCallback);

const query = {
index_permissions: true,
kibana_host: '',
subdomain: 'subdomain',
};

expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/sources/github/prepare?subdomain=subdomain&index_permissions=true'
'/api/workplace_search/org/sources/github/prepare',
{ query }
);
});

Expand Down Expand Up @@ -413,7 +486,7 @@ describe('AddSourceLogic', () => {
http.put
).toHaveBeenCalledWith(
`/api/workplace_search/org/settings/connectors/${sourceConfigData.serviceType}`,
{ body: JSON.stringify({ params }) }
{ body: JSON.stringify(params) }
);

await nextTick();
Expand All @@ -436,7 +509,7 @@ describe('AddSourceLogic', () => {
};

expect(http.post).toHaveBeenCalledWith('/api/workplace_search/org/settings/connectors', {
body: JSON.stringify({ params: createParams }),
body: JSON.stringify(createParams),
});
});

Expand Down Expand Up @@ -515,11 +588,15 @@ describe('AddSourceLogic', () => {
});

it('getSourceConnectData', () => {
const query = {
kibana_host: '',
};

AddSourceLogic.actions.getSourceConnectData('github', jest.fn());

expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/account/sources/github/prepare'
);
expect(
http.get
).toHaveBeenCalledWith('/api/workplace_search/account/sources/github/prepare', { query });
});

it('getSourceReConnectData', () => {
Expand Down
Loading

0 comments on commit 1c4eb55

Please sign in to comment.