Skip to content

Commit

Permalink
Update Secret Action Test Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-logro authored and tekton-robot committed Nov 15, 2019
1 parent 0645b73 commit aad762d
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/actions/secrets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ const data = {
items: [
{
metadata: {
name: 'secret-name',
name: 'default-token-kbn7j',
namespace: 'default',
annotations: undefined,
labels: {
serviceAccount: 'default'
}
},
data: {
username: '[email protected]',
password: '********'
},
resourceVersion: '####',
type: 'userpass'
},
{
metadata: {
name: 'another-token-kbn7j',
namespace: 'default',
annotations: undefined,
labels: {
Expand All @@ -47,15 +63,21 @@ const data = {

const dataFormatted = [
{
name: 'secret-name',
name: 'default-token-kbn7j',
annotations: undefined,
namespace: 'default',
type: 'userpass'
},
{
name: 'another-token-kbn7j',
annotations: undefined,
namespace: 'default',
type: 'userpass'
}
];
const postData = {
metadata: {
name: 'secret-name',
name: 'default-token-kbn7j',
namespace: 'default',
annotations: { 'tekton.dev/git-0': 'https://github.ibm.com' },
labels: {
Expand Down Expand Up @@ -83,6 +105,9 @@ const defaultServiceAccount = {
secrets: [
{
name: 'default-token-kbn7j'
},
{
name: 'another-token-kbn7j'
}
]
};
Expand Down Expand Up @@ -139,7 +164,10 @@ it('fetchSecrets error', async () => {
});

it('deleteSecret', async () => {
const secrets = [{ name: 'secret-name', namespace: 'default' }];
const secrets = [
{ name: 'default-token-kbn7j', namespace: 'default' },
{ name: 'another-token-kbn7j', namespace: 'default' }
];
const middleware = [thunk];
const mockStore = configureStore(middleware);
const store = mockStore();
Expand All @@ -148,6 +176,10 @@ it('deleteSecret', async () => {
.spyOn(selectors, 'getSelectedNamespace')
.mockImplementation(() => namespace);

jest
.spyOn(API, 'getServiceAccounts')
.mockImplementation(() => [defaultServiceAccount]);
jest.spyOn(API, 'updateServiceAccountSecrets').mockImplementation(() => {});
jest.spyOn(API, 'deleteCredential').mockImplementation(() => {});

const expectedActions = [
Expand All @@ -160,11 +192,15 @@ it('deleteSecret', async () => {
});

it('deleteSecret error', async () => {
const secrets = [{ name: 'secret-name', namespace: 'default' }];
const secrets = [{ name: 'default-token-kbn7j', namespace: 'default' }];
const middleware = [thunk];
const mockStore = configureStore(middleware);
const store = mockStore();

jest
.spyOn(API, 'getServiceAccounts')
.mockImplementation(() => [defaultServiceAccount]);
jest.spyOn(API, 'updateServiceAccountSecrets').mockImplementation(() => {});
jest
.spyOn(API, 'deleteCredential')
.mockImplementation(() => Promise.reject());
Expand Down

0 comments on commit aad762d

Please sign in to comment.