Skip to content

Commit

Permalink
Add smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Jan 22, 2020
1 parent 39030af commit b465da8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
14 changes: 12 additions & 2 deletions test/plugin_functional/plugins/core_plugin_b/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { CoreSetup, Plugin, PluginInitializerContext } from 'kibana/public';
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'kibana/public';
import { CorePluginAPluginSetup } from '../../core_plugin_a/public/plugin';

declare global {
Expand Down Expand Up @@ -52,7 +52,17 @@ export class CorePluginBPlugin
};
}

public start() {}
public async start(core: CoreStart, deps: {}) {
return {
sendSystemRequest: async (asSystemRequest: boolean) => {
const response = await core.http.post<string>('/core_plugin_b/system_request', {
asSystemRequest,
});
return `/core_plugin_b/system_request says: "${response}"`;
},
};
}

public stop() {}
}

Expand Down
10 changes: 10 additions & 0 deletions test/plugin_functional/plugins/core_plugin_b/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class CorePluginBPlugin implements Plugin {
return res.ok({ body: `ID: ${req.query.id} - ${req.body.bar.toUpperCase()}` });
}
);

router.post(
{
path: '/core_plugin_b/system_request',
validate: false,
},
async (context, req, res) => {
return res.ok({ body: `System request? ${req.isSystemRequest}` });
}
);
}

public start() {}
Expand Down
10 changes: 10 additions & 0 deletions test/plugin_functional/test_suites/core_plugins/server_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,15 @@ export default function({ getService }: PluginFunctionalProviderContext) {
statusCode: 400,
});
});

it('sets request.isSystemRequest when kbn-system-request header is set', async () => {
await supertest
.post('/core_plugin_b/system_request')
.set('kbn-xsrf', 'anything')
.set('kbn-system-request', 'true')
.send()
.expect(200)
.expect('System request? true');
});
});
}
24 changes: 23 additions & 1 deletion test/plugin_functional/test_suites/core_plugins/ui_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
});
});

describe('have env data provided', function describeIndexTests() {
describe('have env data provided', () => {
before(async () => {
await PageObjects.common.navigateToApp('bar');
});
Expand All @@ -75,5 +75,27 @@ export default function({ getService, getPageObjects }: PluginFunctionalProvider
expect(envData.packageInfo.version).to.be.a('string');
});
});

describe('http fetching', () => {
before(async () => {
await PageObjects.common.navigateToApp('settings');
});

it('should send kbn-system-request header when asSystemRequest: true', async () => {
expect(
await browser.executeAsync(async cb => {
window.__coreProvider.start.plugins.core_plugin_b.sendSystemRequest(true).then(cb);
})
).to.be('/core_plugin_b/system_request says: "System request? true"');
});

it('should not send kbn-system-request header when asSystemRequest: false', async () => {
expect(
await browser.executeAsync(async cb => {
window.__coreProvider.start.plugins.core_plugin_b.sendSystemRequest(false).then(cb);
})
).to.be('/core_plugin_b/system_request says: "System request? false"');
});
});
});
}

0 comments on commit b465da8

Please sign in to comment.