Skip to content

Commit

Permalink
Migrate Newsfeed test plugin (#66059)
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed May 12, 2020
1 parent 878dd21 commit 7eb688d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 145 deletions.
6 changes: 6 additions & 0 deletions test/common/fixtures/plugins/newsfeed/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "newsfeed-fixtures",
"version": "kibana",
"server": true,
"ui": false
}
126 changes: 0 additions & 126 deletions test/common/fixtures/plugins/newsfeed/newsfeed_simulation.ts

This file was deleted.

7 changes: 0 additions & 7 deletions test/common/fixtures/plugins/newsfeed/package.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@
* under the License.
*/

import Hapi from 'hapi';
import { initPlugin as initNewsfeed } from './newsfeed_simulation';
import { NewsFeedSimulatorPlugin } from './plugin';

const NAME = 'newsfeed-FTS-external-service-simulators';

// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
name: NAME,
init: (server: Hapi.Server) => {
initNewsfeed(server, `/api/_${NAME}`);
},
});
export function plugin() {
return new NewsFeedSimulatorPlugin();
}
96 changes: 96 additions & 0 deletions test/common/fixtures/plugins/newsfeed/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { CoreSetup, Plugin } from 'kibana/server';

const PATH = '/api/_newsfeed-FTS-external-service-simulators';

export class NewsFeedSimulatorPlugin implements Plugin {
public setup({ http }: CoreSetup) {
const router = http.createRouter();

router.get(
{
path: `${PATH}/kibana/v{version}.json`,
validate: { params: schema.object({ version: schema.string() }) },
options: { authRequired: false },
},
(context, req, res) => {
return res.ok({ body: this.mockNewsfeed(req.params.version) });
}
);

router.get(
{
path: `${PATH}/kibana/crash.json`,
validate: false,
options: { authRequired: false },
},
(context, req, res) => {
return res.internalError({ body: new Error('Internal server error') });
}
);
}

public start() {}

private mockNewsfeed(version: string) {
return {
items: [
{
title: { en: `You are functionally testing the newsfeed widget with fixtures!` },
description: { en: 'See test/common/fixtures/plugins/newsfeed/newsfeed_simulation' },
link_text: { en: 'Generic feed-viewer could go here' },
link_url: { en: 'https://feeds.elastic.co' },
languages: null,
badge: null,
image_url: null,
publish_on: '2019-06-21T00:00:00',
expire_on: '2040-01-31T00:00:00',
hash: '39ca7d409c7eb25f4c69a5a6a11309b2f5ced7ca3f9b3a0109517126e0fd91ca',
},
{
title: { en: 'Staging too!' },
description: { en: 'Hello world' },
link_text: { en: 'Generic feed-viewer could go here' },
link_url: { en: 'https://feeds-staging.elastic.co' },
languages: null,
badge: null,
image_url: null,
publish_on: '2019-06-21T00:00:00',
expire_on: '2040-01-31T00:00:00',
hash: 'db445c9443eb50ea2eb15f20edf89cf0f7dac2b058b11cafc2c8c288b6e4ce2a',
},
{
title: { en: 'This item is expired!' },
description: { en: 'This should not show up.' },
link_text: { en: 'Generic feed-viewer could go here' },
link_url: { en: 'https://feeds-staging.elastic.co' },
languages: null,
badge: null,
image_url: null,
publish_on: '2019-06-21T00:00:00',
expire_on: '2019-12-31T00:00:00',
hash: 'db445c9443eb50ea2eb15f20edf89cf0f7dac2b058b11cafc2c8c288b6e4ce2a',
},
],
};
}
}

0 comments on commit 7eb688d

Please sign in to comment.