Fix Cypress tests to accommodate new admin UI URI.

This commit is contained in:
Kailash Nadh 2021-09-25 12:44:09 +05:30
parent 9f8e9c018b
commit 9f3eb7e4a4
6 changed files with 29 additions and 20 deletions

View file

@ -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"
}

View file

@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');
describe('Bounces', () => {
let subs = [];
@ -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(() => {
@ -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)
});
@ -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 });
}
});

View file

@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');
describe('Subscribers', () => {
it('Opens campaigns page', () => {
cy.resetDB();
@ -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');
@ -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);
@ -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);

View file

@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');
describe('Forms', () => {
it('Opens forms page', () => {
cy.resetDB();
@ -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.
@ -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.

View file

@ -1,3 +1,5 @@
const apiUrl = Cypress.env('apiUrl');
describe('Templates', () => {
it('Opens settings page', () => {
cy.resetDB();
@ -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);

View file

@ -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,
@ -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));