Skip to content

Commit

Permalink
Add API, actions, and reducers to get Triggers resources
Browse files Browse the repository at this point in the history
  • Loading branch information
a-roberts committed Nov 1, 2019
1 parent 9f7aa92 commit 9168675
Show file tree
Hide file tree
Showing 12 changed files with 504 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/actions/eventListeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 { getEventListener, getEventListeners } from '../api';
import {
fetchNamespacedCollection,
fetchNamespacedResource
} from './actionCreators';

export function fetchEventListener({ name, namespace }) {
return fetchNamespacedResource('EventListener', getEventListener, {
name,
namespace
});
}

export function fetchEventListeners({ namespace } = {}) {
return fetchNamespacedCollection('EventListener', getEventListeners, {
namespace
});
}
52 changes: 52 additions & 0 deletions src/actions/eventListeners.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 * as API from '../api';
import * as creators from './actionCreators';
import {
fetchEventListener,
fetchEventListeners
} from './eventListeners';

it('fetchEventListener', async () => {
jest.spyOn(creators, 'fetchNamespacedResource');
const name = 'EventListenerName';
const namespace = 'namespace';
fetchEventListener({ name, namespace });
expect(creators.fetchNamespacedResource).toHaveBeenCalledWith(
'EventListener',
API.getEventListener,
{ name, namespace }
);
});

it('fetchEventListeners', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
const namespace = 'namespace';
fetchEventListeners({ namespace });
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'EventListener',
API.getEventListeners,
{ namespace }
);
});

it('fetchEventListeners no namespace', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
fetchEventListeners();
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'EventListener',
API.getEventListeners,
{ namespace: undefined }
);
});
32 changes: 32 additions & 0 deletions src/actions/triggerBindings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 { getTriggerBinding, getTriggerBindings } from '../api';
import {
fetchNamespacedCollection,
fetchNamespacedResource
} from './actionCreators';

export function fetchTriggerBinding({ name, namespace }) {
return fetchNamespacedResource('TriggerBinding', getTriggerBinding, {
name,
namespace
});
}

export function fetchTriggerBindings({ filters, namespace } = {}) {
return fetchNamespacedCollection('TriggerBinding', getTriggerBindings, {
filters,
namespace
});
}
52 changes: 52 additions & 0 deletions src/actions/triggerBindings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 * as API from '../api';
import * as creators from './actionCreators';
import {
fetchTriggerBinding,
fetchTriggerBindings
} from './triggerBindings';

it('fetchTriggerBinding', async () => {
jest.spyOn(creators, 'fetchNamespacedResource');
const name = 'TriggerBindingName';
const namespace = 'namespace';
fetchTriggerBinding({ name, namespace });
expect(creators.fetchNamespacedResource).toHaveBeenCalledWith(
'TriggerBinding',
API.getTriggerBinding,
{ name, namespace }
);
});

it('fetchTriggerBindings', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
const namespace = 'namespace';
fetchTriggerBindings({ namespace });
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'TriggerBinding',
API.getTriggerBindings,
{ namespace }
);
});

it('fetchTriggerBindings no namespace', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
fetchTriggerBindings();
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'TriggerBinding',
API.getTriggerBindings,
{ namespace: undefined }
);
});
31 changes: 31 additions & 0 deletions src/actions/triggerTemplates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 { getTriggerTemplate, getTriggerTemplates } from '../api';
import {
fetchNamespacedCollection,
fetchNamespacedResource
} from './actionCreators';

export function fetchTriggerTemplate({ name, namespace }) {
return fetchNamespacedResource('TriggerTemplate', getTriggerTemplate, {
name,
namespace
});
}

export function fetchTriggerTemplates({ namespace } = {}) {
return fetchNamespacedCollection('TriggerTemplate', getTriggerTemplates, {
namespace
});
}
52 changes: 52 additions & 0 deletions src/actions/triggerTemplates.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 * as API from '../api';
import * as creators from './actionCreators';
import {
fetchTriggerTemplate,
fetchTriggerTemplates
} from './triggerTemplates';

it('fetchTriggerTemplate', async () => {
jest.spyOn(creators, 'fetchNamespacedResource');
const name = 'TriggerTemplateName';
const namespace = 'namespace';
fetchTriggerTemplate({ name, namespace });
expect(creators.fetchNamespacedResource).toHaveBeenCalledWith(
'TriggerTemplate',
API.getTriggerTemplate,
{ name, namespace }
);
});

it('fetchTriggerTemplates', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
const namespace = 'namespace';
fetchTriggerTemplates({ namespace });
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'TriggerTemplate',
API.getTriggerTemplates,
{ namespace }
);
});

it('fetchTriggerTemplates no namespace', async () => {
jest.spyOn(creators, 'fetchNamespacedCollection');
fetchTriggerTemplates();
expect(creators.fetchNamespacedCollection).toHaveBeenCalledWith(
'TriggerTemplate',
API.getTriggerTemplates,
{ namespace: undefined }
);
});
30 changes: 30 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,33 @@ export async function determineInstallNamespace() {
});
return response;
}

export function getTriggerTemplates({ namespace } = {}) {
const uri = getTektonAPI('triggertemplates', { namespace });
return get(uri).then(checkData);
}

export function getTriggerTemplate( {name, namespace }) {
const uri = getTektonAPI('triggertemplates', { name, namespace });
return get(uri);
}

export function getTriggerBindings({ namespace } = {}) {
const uri = getTektonAPI('triggerbindings', { namespace });
return get(uri).then(checkData);
}

export function getTriggerBinding( {name, namespace }) {
const uri = getTektonAPI('triggerbindings', { name, namespace });
return get(uri);
}

export function getEventListeners({ namespace } = {}) {
const uri = getTektonAPI('eventlisteners', { namespace });
return get(uri).then(checkData);
}

export function getEventListener( {name, namespace }) {
const uri = getTektonAPI('eventlisteners', { name, namespace });
return get(uri);
}
64 changes: 64 additions & 0 deletions src/api/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,67 @@ it('getResource', () => {
fetchMock.restore();
});
});


it('getTriggerTemplates', () => {
const data = {
items: 'triggerTemplates'
};
fetchMock.get(/triggertemplates/, data);
return index.getTriggerTemplates().then(triggerTemplates => {
expect(triggerTemplates).toEqual(data.items);
fetchMock.restore();
});
});

it('getTriggerTemplate', () => {
const name = 'foo';
const data = { fake: 'triggerTemplate' };
fetchMock.get(`end:${name}`, data);
return index.getTriggerTemplate({ name }).then(triggerTemplate => {
expect(triggerTemplate).toEqual(data);
fetchMock.restore();
});
});

it('getTriggerBinding', () => {
const name = 'foo';
const data = { fake: 'triggerBinding' };
fetchMock.get(`end:${name}`, data);
return index.getTriggerBinding({ name }).then(triggerBinding => {
expect(triggerBinding).toEqual(data);
fetchMock.restore();
});
});

it('getTriggerBindings', () => {
const data = {
items: 'triggerBindings'
};
fetchMock.get(/triggerbindings/, data);
return index.getTriggerBindings().then(triggerBindings => {
expect(triggerBindings).toEqual(data.items);
fetchMock.restore();
});
});

it('getEventListener', () => {
const name = 'foo';
const data = { fake: 'eventListener' };
fetchMock.get(`end:${name}`, data);
return index.getEventListener({ name }).then(eventListener => {
expect(eventListener).toEqual(data);
fetchMock.restore();
});
});

it('getEventListeners', () => {
const data = {
items: 'eventListeners'
};
fetchMock.get(/eventlisteners/, data);
return index.getEventListeners().then(eventListeners => {
expect(eventListeners).toEqual(data.items);
fetchMock.restore();
});
});
33 changes: 33 additions & 0 deletions src/reducers/eventListeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2019 The Tekton Authors
Licensed 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 { createNamespacedReducer } from './reducerCreators';
import { getCollection, getResource } from './selectorCreators';

export default () => createNamespacedReducer({ type: 'EventListener' });

export function getEventListeners(state, namespace) {
return getCollection(state, namespace);
}

export function getEventListener(state, name, namespace) {
return getResource(state, name, namespace);
}

export function getEventListenersErrorMessage(state) {
return state.errorMessage;
}

export function isFetchingEventListeners(state) {
return state.isFetching;
}
Loading

0 comments on commit 9168675

Please sign in to comment.