Skip to content

Commit

Permalink
Merge pull request #6159 from transcom/nt-mb-6581-add-updateWebhookSu…
Browse files Browse the repository at this point in the history
…bsction-to-page

MB-6581-add-webhook-subscription-page
  • Loading branch information
NamibiaTorres authored Mar 18, 2021
2 parents 590050e + 1682d1d commit 58a8f20
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
51 changes: 44 additions & 7 deletions cypress/integration/admin/webhookSubscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,43 @@ describe('WebhookSubscriptions Details Show Page', function () {
});
});

describe('WebhookSubscriptions Details Edit Page', function () {
before(() => {
cy.prepareAdminApp();
});

it('pulls up edit page for a webhook subscription', function () {
cy.signInAsNewAdminUser();
cy.get('a[href*="system/webhook_subscriptions"]').click();
cy.url().should('eq', adminBaseURL + '/system/webhook_subscriptions');
cy.get('tr[resource="webhook_subscriptions"]').first().click();

// check that the page pulls up the right webhook subscription
cy.get('.ra-field-id > div > label')
.first()
.next()
.then(($id) => {
cy.get('a').contains('Edit').click();
cy.url().should('eq', adminBaseURL + '/system/webhook_subscriptions/' + $id.text());
});

// check labels on edit page
const labels = ['Id', 'Subscriber', 'Status', 'Event key', 'Callback url', 'Created at', 'Updated at', 'Severity'];
labels.forEach((label) => {
cy.get('label').contains(label);
});

// Change webhook subscription status
cy.get('div[id="status"]').click();
cy.get('#menu-status ul > li[data-value=DISABLED').click();
cy.get('button').contains('Save').click();

// Check that the webhook subscription status was changed for the first webhook subscription in the list
cy.url().should('eq', adminBaseURL + '/system/webhook_subscriptions');
cy.get('td.column-status > span').first().should('contain', 'DISABLED');
});
});

describe('Webhook Subscription Create Page', function () {
before(() => {
cy.prepareAdminApp();
Expand All @@ -64,16 +101,16 @@ describe('Webhook Subscription Create Page', function () {
cy.get('button').contains('Save').click();

// redirected to details page
cy.get('.ra-field-id span.MuiTypography-root')
cy.get('input[id="id"]')
.invoke('text')
.then((subID) => {
cy.get('#react-admin-title').contains('Webhook Subscription ID: ' + subID);
cy.get('#react-admin-title').contains('Webhook subscription #' + subID);
});

cy.get('.ra-field-subscriberId').contains('5db13bb4-6d29-4bdb-bc81-262f4513ecf6');
cy.get('.ra-field-eventKey').contains('PaymentRequest.Update');
cy.get('.ra-field-callbackUrl').contains('https://test1.com');
cy.get('.ra-field-status').contains('ACTIVE');
cy.get('.ra-field-severity').contains('0');
cy.get('input[id="subscriberId"]').type('5db13bb4-6d29-4bdb-bc81-262f4513ecf6');
cy.get('input[id="eventKey"]').type('PaymentRequest.Update');
cy.get('input[id="callbackUrl"]').type('https://test1.com');
cy.get('div[id="status"]').should('contain', 'Active');
cy.get('div[id="severity"]').should('contain', '0');
});
});
44 changes: 44 additions & 0 deletions src/pages/Admin/WebhookSubscriptions/WebhookSubscriptionEdit.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { Edit, required, SaveButton, SelectInput, SimpleForm, TextInput, Toolbar } from 'react-admin';

import { WEBHOOK_SUBSCRIPTION_STATUS } from 'shared/constants';

const WebhookSubscriptionEditToolbar = (props) => (
<Toolbar {...props}>
<SaveButton />
</Toolbar>
);

const WebhookSubscriptionEdit = (props) => (
/* eslint-disable-next-line react/jsx-props-no-spreading */
<Edit {...props}>
<SimpleForm toolbar={<WebhookSubscriptionEditToolbar />}>
<TextInput source="id" disabled />
<TextInput label="Subscriber Id" source="subscriberId" validate={required()} />
<TextInput source="eventKey" validate={required()} />
<TextInput source="callbackUrl" validate={required()} />
<SelectInput
source="severity"
choices={[
{ id: 0, name: 0 },
{ id: 1, name: 1 },
{ id: 2, name: 2 },
{ id: 3, name: 3 },
{ id: 4, name: 4 },
]}
/>
<SelectInput
source="status"
choices={[
{ id: WEBHOOK_SUBSCRIPTION_STATUS.ACTIVE, name: 'Active' },
{ id: WEBHOOK_SUBSCRIPTION_STATUS.DISABLED, name: 'Disabled' },
{ id: WEBHOOK_SUBSCRIPTION_STATUS.FAILING, name: 'Failing' },
]}
/>
<TextInput source="createdAt" disabled />
<TextInput source="updatedAt" disabled />
</SimpleForm>
</Edit>
);

export default WebhookSubscriptionEdit;
2 changes: 2 additions & 0 deletions src/scenes/SystemAdmin/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import UserEdit from 'pages/Admin/Users/UserEdit';
import WebhookSubscriptionList from 'pages/Admin/WebhookSubscriptions/WebhookSubscriptionsList';
import WebhookSubscriptionShow from 'pages/Admin/WebhookSubscriptions/WebhookSubscriptionShow';
import WebhookSubscriptionCreate from 'pages/Admin/WebhookSubscriptions/WebhookSubscriptionCreate';
import WebhookSubscriptionEdit from '../../pages/Admin/WebhookSubscriptions/WebhookSubscriptionEdit';

import styles from './Home.module.scss';
import * as Cookies from 'js-cookie';
Expand Down Expand Up @@ -103,6 +104,7 @@ const Home = () => (
show={WebhookSubscriptionShow}
create={WebhookSubscriptionCreate}
list={WebhookSubscriptionList}
edit={WebhookSubscriptionEdit}
/>
</Admin>
</div>
Expand Down

0 comments on commit 58a8f20

Please sign in to comment.