diff --git a/src/actions/eventListeners.js b/src/actions/eventListeners.js new file mode 100644 index 000000000..9373d9b82 --- /dev/null +++ b/src/actions/eventListeners.js @@ -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 + }); +} diff --git a/src/actions/eventListeners.test.js b/src/actions/eventListeners.test.js new file mode 100644 index 000000000..cb18f18a6 --- /dev/null +++ b/src/actions/eventListeners.test.js @@ -0,0 +1,49 @@ +/* +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 } + ); +}); diff --git a/src/actions/secrets.js b/src/actions/secrets.js index 3a1c225c6..a74df8d8c 100644 --- a/src/actions/secrets.js +++ b/src/actions/secrets.js @@ -78,7 +78,10 @@ export function deleteSecret(secrets) { which is the only way to remove secrets otherwise using the patch API */ // For each namespace there are secrets in - namespacesToSecretsMap.forEach(async function(value, namespace) { + namespacesToSecretsMap.forEach(async function handleSecretUnpatching( + value, + namespace + ) { // Get all the service accounts in the namespace const serviceAccounts = await getServiceAccounts({ namespace diff --git a/src/actions/triggerBindings.js b/src/actions/triggerBindings.js new file mode 100644 index 000000000..f2970b978 --- /dev/null +++ b/src/actions/triggerBindings.js @@ -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 + }); +} diff --git a/src/actions/triggerBindings.test.js b/src/actions/triggerBindings.test.js new file mode 100644 index 000000000..0bb930f8c --- /dev/null +++ b/src/actions/triggerBindings.test.js @@ -0,0 +1,49 @@ +/* +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 } + ); +}); diff --git a/src/actions/triggerTemplates.js b/src/actions/triggerTemplates.js new file mode 100644 index 000000000..cce7aef0f --- /dev/null +++ b/src/actions/triggerTemplates.js @@ -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 + }); +} diff --git a/src/actions/triggerTemplates.test.js b/src/actions/triggerTemplates.test.js new file mode 100644 index 000000000..4f826852a --- /dev/null +++ b/src/actions/triggerTemplates.test.js @@ -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 } + ); +}); diff --git a/src/api/index.js b/src/api/index.js index c0440d3a8..e68442565 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -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); +} diff --git a/src/api/index.test.js b/src/api/index.test.js index 0532a7b5c..38aa72aba 100644 --- a/src/api/index.test.js +++ b/src/api/index.test.js @@ -644,3 +644,66 @@ 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(); + }); +}); diff --git a/src/reducers/eventListeners.js b/src/reducers/eventListeners.js new file mode 100644 index 000000000..875c438db --- /dev/null +++ b/src/reducers/eventListeners.js @@ -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; +} diff --git a/src/reducers/triggerBindings.js b/src/reducers/triggerBindings.js new file mode 100644 index 000000000..698cc553d --- /dev/null +++ b/src/reducers/triggerBindings.js @@ -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: 'TriggerBinding' }); + +export function getTriggerBindings(state, namespace) { + return getCollection(state, namespace); +} + +export function getTriggerBinding(state, name, namespace) { + return getResource(state, name, namespace); +} + +export function getTriggerBindingsErrorMessage(state) { + return state.errorMessage; +} + +export function isFetchingTriggerBindings(state) { + return state.isFetching; +} diff --git a/src/reducers/triggerTemplates.js b/src/reducers/triggerTemplates.js new file mode 100644 index 000000000..f33681bb6 --- /dev/null +++ b/src/reducers/triggerTemplates.js @@ -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: 'TriggerTemplate' }); + +export function getTriggerTemplates(state, namespace) { + return getCollection(state, namespace); +} + +export function getTriggerTemplate(state, name, namespace) { + return getResource(state, name, namespace); +} + +export function getTriggerTemplatesErrorMessage(state) { + return state.errorMessage; +} + +export function isFetchingTriggerTemplates(state) { + return state.isFetching; +} diff --git a/src/reducers/triggerTemplates.test.js b/src/reducers/triggerTemplates.test.js new file mode 100644 index 000000000..d51b17759 --- /dev/null +++ b/src/reducers/triggerTemplates.test.js @@ -0,0 +1,61 @@ +/* +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 reducerCreators from './reducerCreators'; +import * as selectorCreators from './selectorCreators'; +import createReducer, * as selectors from './triggerTemplates'; + +const name = 'pipeline resource name'; +const namespace = 'default'; +const state = { fake: 'state' }; + +it('creates a namespaced reducer for the correct type', () => { + const type = 'TriggerTemplate'; + jest.spyOn(reducerCreators, 'createNamespacedReducer'); + createReducer(); + expect(reducerCreators.createNamespacedReducer).toHaveBeenCalledWith({ + type + }); +}); + +it('getTriggerTemplates', () => { + const collection = { fake: 'collection' }; + jest + .spyOn(selectorCreators, 'getCollection') + .mockImplementation(() => collection); + expect(selectors.getTriggerTemplates(state, namespace)).toEqual(collection); +}); + +it('getTriggerTemplate', () => { + const resource = { fake: 'resource' }; + jest + .spyOn(selectorCreators, 'getResource') + .mockImplementation(() => resource); + expect(selectors.getTriggerTemplate(state, name, namespace)).toEqual( + resource + ); +}); + +it('getTriggerTemplatesErrorMessage', () => { + const errorMessage = 'errorMessage'; + expect(selectors.getTriggerTemplatesErrorMessage({ errorMessage })).toEqual( + errorMessage + ); +}); + +it('isFetchingTriggerTemplates', () => { + const isFetching = 'isFetching'; + expect(selectors.isFetchingTriggerTemplates({ isFetching })).toEqual( + isFetching + ); +});