Skip to content

Commit

Permalink
Fix Cypress tests to accommodate new admin UI URI.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Sep 25, 2021
1 parent 9f8e9c0 commit 9f3eb7e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
5 changes: 3 additions & 2 deletions frontend/cypress.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"baseUrl": "http://localhost:9000",
"baseUrl": "http://localhost:9000/admin",
"env": {
"server_init_command": "pkill -9 listmonk | cd ../ && ./listmonk --install --yes && ./listmonk > /dev/null 2>/dev/null &",
"apiUrl": "http://localhost:9000",
"serverInitCmd": "pkill -9 listmonk | cd ../ && ./listmonk --install --yes && ./listmonk > /dev/null 2>/dev/null &",
"username": "listmonk",
"password": "listmonk"
}
Expand Down
14 changes: 8 additions & 6 deletions frontend/cypress/integration/bounces.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');

describe('Bounces', () => {
let subs = [];

Expand All @@ -18,7 +20,7 @@ describe('Bounces', () => {
it('Post bounces', () => {
// Get campaign.
let camp = {};
cy.request('/api/campaigns').then((resp) => {
cy.request(`${apiUrl}/api/campaigns`).then((resp) => {
camp = resp.body.data.results[0];
})
cy.then(() => {
Expand All @@ -27,7 +29,7 @@ describe('Bounces', () => {


// Get subscribers.
cy.request('/api/subscribers').then((resp) => {
cy.request(`${apiUrl}/api/subscribers`).then((resp) => {
subs = resp.body.data.results;
console.log(subs)
});
Expand All @@ -36,12 +38,12 @@ describe('Bounces', () => {
console.log(`got ${subs.length} subscribers`);

// Post bounces. Blocklist the 1st sub.
cy.request('POST', '/webhooks/bounce', { source: "api", type: "hard", email: subs[0].email });
cy.request('POST', '/webhooks/bounce', { source: "api", type: "hard", campaign_uuid: camp.uuid, email: subs[0].email });
cy.request('POST', '/webhooks/bounce', { source: "api", type: "hard", campaign_uuid: camp.uuid, subscriber_uuid: subs[0].uuid });
cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: "api", type: "hard", email: subs[0].email });
cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: "api", type: "hard", campaign_uuid: camp.uuid, email: subs[0].email });
cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: "api", type: "hard", campaign_uuid: camp.uuid, subscriber_uuid: subs[0].uuid });

for (let i = 0; i < 2; i++) {
cy.request('POST', '/webhooks/bounce', { source: "api", type: "soft", campaign_uuid: camp.uuid, subscriber_uuid: subs[1].uuid });
cy.request('POST', `${apiUrl}/webhooks/bounce`, { source: "api", type: "soft", campaign_uuid: camp.uuid, subscriber_uuid: subs[1].uuid });
}
});

Expand Down
8 changes: 5 additions & 3 deletions frontend/cypress/integration/campaigns.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');

describe('Subscribers', () => {
it('Opens campaigns page', () => {
cy.resetDB();
Expand Down Expand Up @@ -50,7 +52,7 @@ describe('Subscribers', () => {
cy.wait(250);

// Verify the changes.
cy.request('/api/campaigns/1').should((response) => {
cy.request(`${apiUrl}/api/campaigns/1`).should((response) => {
const { data } = response.body;
expect(data.status).to.equal('scheduled');
expect(data.name).to.equal('new-name');
Expand Down Expand Up @@ -112,7 +114,7 @@ describe('Subscribers', () => {
let n = 0;
cTypes.forEach((c) => {
lists.forEach((l) => {
// Click the 'new button'
// Click the 'new button'
cy.get('[data-cy=btn-new]').click();
cy.wait(100);

Expand Down Expand Up @@ -165,7 +167,7 @@ describe('Subscribers', () => {
});

// Fetch the campaigns API and verfiy the values that couldn't be verified on the table UI.
cy.request('/api/campaigns?order=asc&order_by=created_at').should((response) => {
cy.request(`${apiUrl}/api/campaigns?order=asc&order_by=created_at`).should((response) => {
const { data } = response.body;
expect(data.total).to.equal(lists.length * cTypes.length);

Expand Down
6 changes: 4 additions & 2 deletions frontend/cypress/integration/forms.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');

describe('Forms', () => {
it('Opens forms page', () => {
cy.resetDB();
Expand Down Expand Up @@ -36,7 +38,7 @@ describe('Forms', () => {

it('Subscribes from public form page', () => {
// Create a public test list.
cy.request('POST', '/api/lists', { name: 'test-list', type: 'public', optin: 'single' });
cy.request('POST', `${apiUrl}/api/lists`, { name: 'test-list', type: 'public', optin: 'single' });

// Open the public page and subscribe to alternating lists multiple times.
// There should be no errors and two new subscribers should be subscribed to two lists.
Expand All @@ -53,7 +55,7 @@ describe('Forms', () => {
}

// Verify form subscriptions.
cy.request('/api/subscribers').should((response) => {
cy.request(`${apiUrl}/api/subscribers`).should((response) => {
const { data } = response.body;

// Two new + two dummy subscribers that are there by default.
Expand Down
4 changes: 3 additions & 1 deletion frontend/cypress/integration/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');

describe('Templates', () => {
it('Opens settings page', () => {
cy.resetDB();
Expand Down Expand Up @@ -27,7 +29,7 @@ describe('Templates', () => {
cy.wait(250);

// Verify the changes.
cy.request('/api/settings').should((response) => {
cy.request(`${apiUrl}/api/settings`).should((response) => {
const { data } = response.body;
expect(data['app.root_url']).to.equal(rootURL);
expect(data['app.favicon_url']).to.equal(faveURL);
Expand Down
12 changes: 6 additions & 6 deletions frontend/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Cypress.Commands.add('resetDB', () => {
// in the background. If the DB is reset without restartin listmonk,
// the live Postgres connections in the app throw errors because the
// schema changes midway.
cy.exec(Cypress.env('server_init_command'));
cy.exec(Cypress.env('serverInitCmd'));
});

// Takes a th class selector of a Buefy table, clicks it sorting the table,
Expand Down Expand Up @@ -35,8 +35,8 @@ Cypress.Commands.add('clickMenu', (...selectors) => {
});

// https://www.nicknish.co/blog/cypress-targeting-elements-inside-iframes
Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe, callback = () => {}) => cy
.wrap($iframe)
.should((iframe) => expect(iframe.contents().find('body')).to.exist)
.then((iframe) => cy.wrap(iframe.contents().find('body')))
.within({}, callback));
Cypress.Commands.add('iframe', { prevSubject: 'element' }, ($iframe, callback = () => { }) => cy
.wrap($iframe)
.should((iframe) => expect(iframe.contents().find('body')).to.exist)
.then((iframe) => cy.wrap(iframe.contents().find('body')))
.within({}, callback));

0 comments on commit 9f3eb7e

Please sign in to comment.