Skip to content

Commit

Permalink
[4.4] api tests contact (#41301)
Browse files Browse the repository at this point in the history
  • Loading branch information
heelc29 committed Aug 9, 2023
1 parent 6eb9108 commit 4517709
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 106 deletions.
31 changes: 28 additions & 3 deletions tests/System/integration/api/com_contact/Categories.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
describe('Test that content categories API endpoint', () => {
describe('Test that contact categories API endpoint', () => {
afterEach(() => cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'automated test contact category'"));

it('can display a list of categories', () => {
cy.db_createCategory({ title: 'automated test category', extension: 'com_contact' })
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.db_createContact({ name: 'automated test contact', catid: id }))
.then(() => cy.api_get('/contacts/categories'))
.then((response) => cy.api_responseContains(response, 'title', 'automated test category'));
.then((response) => cy.api_responseContains(response, 'title', 'automated test contact category'));
});

it('can display a single category', () => {
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.api_get(`/contacts/categories/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test contact category'));
});

it('can create a category', () => {
cy.api_post('/contacts/categories', { title: 'automated test contact category' })
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test contact category'));
});

it('can update a category', () => {
cy.db_createCategory({ title: 'automated test contact category', extension: 'com_contact' })
.then((id) => cy.api_patch(`/contacts/categories/${id}`, { title: 'updated automated test contact category' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test contact category'));
});
});
33 changes: 32 additions & 1 deletion tests/System/integration/api/com_contact/Contacts.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('Test that contacts API endpoint', () => {
beforeEach(() => cy.task('clearEmails'));
afterEach(() => cy.task('queryDB', 'DELETE FROM #__contact_details'));

it('can deliver a list of contacts', () => {
Expand All @@ -9,8 +10,16 @@ describe('Test that contacts API endpoint', () => {
.should('include', 'automated test contact'));
});

it('can deliver a single contact', () => {
cy.db_createContact({ name: 'automated test contact' })
.then((contact) => cy.api_get(`/contacts/${contact.id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('name')
.should('include', 'automated test contact'));
});

it('can create a contact', () => {
cy.db_createCategory({ extension: 'com_contacts' })
cy.db_createCategory({ extension: 'com_contact' })
.then((categoryId) => cy.api_post('/contacts', {
name: 'automated test contact',
alias: 'test-contact',
Expand All @@ -35,4 +44,26 @@ describe('Test that contacts API endpoint', () => {
cy.db_createContact({ name: 'automated test contact', published: -2 })
.then((contact) => cy.api_delete(`/contacts/${contact.id}`));
});

it('can submit a contact form', () => {
cy.db_getUserId().then((id) => cy.db_createContact({ name: 'automated test contact', user_id: id, params: '{"show_email_form":"1"}' }))
.then((contact) => cy.api_post(`/contacts/form/${contact.id}`, {
contact_name: Cypress.env('name'),
contact_email: Cypress.env('email'),
contact_subject: 'automated test subject',
contact_message: 'automated test message',
}))
.then((response) => cy.wrap(response).its('status')
.should('equal', 200));

cy.task('getMails').then((mails) => {
cy.wrap(mails).should('have.lengthOf', 1);
cy.wrap(mails[0].sender).should('equal', Cypress.env('email'));
cy.wrap(mails[0].receivers).should('have.property', Cypress.env('email'));
cy.wrap(mails[0].headers.subject).should('equal', `${Cypress.env('sitename')}: automated test subject`);
cy.wrap(mails[0].body).should('have.string', 'This is an enquiry email via');
cy.wrap(mails[0].body).should('have.string', `${Cypress.env('name')} <${Cypress.env('email')}>`);
cy.wrap(mails[0].body).should('have.string', 'automated test message');
});
});
});
112 changes: 61 additions & 51 deletions tests/System/integration/api/com_contact/Field_Group.cy.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
describe('Test that group field contact API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__fields_groups'));

it('can deliver a list of group fields', () => {
cy.db_createFieldGroup({ title: 'automated test group field', context: 'com_contact.contact' })
.then(() => cy.api_get('/fields/groups/contacts/contact'))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', 'automated test group field'));
});
['contact', 'mail', 'categories'].forEach((context) => {
it(`can deliver a list of group fields (${context})`, () => {
cy.db_createFieldGroup({ title: `automated test group field contacts ${context}`, context: `com_contact.${context}` })
.then(() => cy.api_get(`/fields/groups/contacts/${context}`))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it.only('can create a group field', () => {
cy.api_post('/fields/groups/contacts/contact', {
title: 'automated test group field',
access: 1,
context: 'com_contact.contact',
default_value: '',
description: '',
group_id: 0,
label: 'contact group field',
language: '*',
name: 'contact-group_field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test group field'));
});
it(`can deliver a single group field (${context})`, () => {
cy.db_createFieldGroup({ title: `automated test group field contacts ${context}`, context: `com_contact.${context}` })
.then((id) => cy.api_get(`/fields/groups/contacts/${context}/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it('can update a group field', () => {
cy.db_createFieldGroup({ title: 'automated test group field', access: 1, context: 'com_contact.contact' })
.then((id) => cy.api_patch(`/fields/groups/contacts/contact/${id}`, { title: 'updated automated test group field', context: 'com_contact.contact' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test group field'));
});
it(`can create a group field (${context})`, () => {
cy.api_post(`/fields/groups/contacts/${context}`, {
title: `automated test group field contacts ${context}`,
access: 1,
context: `com_contact.${context}`,
default_value: '',
description: '',
group_id: 0,
label: 'contact group field',
language: '*',
name: 'contact-group_field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test group field contacts ${context}`));
});

it(`can update a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', access: 1, context: `com_contact.${context}` })
.then((id) => cy.api_patch(`/fields/groups/contacts/${context}/${id}`, { title: `updated automated test group field ${context}` }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `updated automated test group field ${context}`));
});

it('can delete a group field', () => {
cy.db_createFieldGroup({ title: 'automated test group field', state: -2 })
.then((id) => cy.api_delete(`/fields/groups/contacts/contact/${id}`));
it(`can delete a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', context: `com_contact.${context}`, state: -2 })
.then((id) => cy.api_delete(`/fields/groups/contacts/${context}/${id}`));
});
});
});
112 changes: 61 additions & 51 deletions tests/System/integration/api/com_contact/Fields.cy.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,69 @@
describe('Test that field contact API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__fields'));

it('can deliver a list of fields', () => {
cy.db_createField({ title: 'automated test field', context: 'com_contact.contact' })
.then(() => cy.api_get('/fields/contacts/contact'))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', 'automated test field'));
});
['contact', 'mail', 'categories'].forEach((context) => {
it(`can deliver a list of fields (${context})`, () => {
cy.db_createField({ title: `automated test field contacts ${context}`, context: `com_contact.${context}` })
.then(() => cy.api_get(`/fields/contacts/${context}`))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', `automated test field contacts ${context}`));
});

it('can create a field', () => {
cy.api_post('/fields/contacts/contact', {
title: 'automated test field',
access: 1,
context: 'com_contact.contact',
default_value: '',
description: '',
group_id: 0,
label: 'contact field',
language: '*',
name: 'contact-field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test field'));
});
it(`can deliver a single field (${context})`, () => {
cy.db_createField({ title: `automated test field contacts ${context}`, context: `com_contact.${context}` })
.then((id) => cy.api_get(`/fields/contacts/${context}/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test field contacts ${context}`));
});

it('can update a field', () => {
cy.db_createField({ title: 'automated test field', context: 'com_contact.contact' })
.then((id) => cy.api_patch(`/fields/contacts/contact/${id}`, { title: 'updated automated test field' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test field'));
});
it(`can create a field (${context})`, () => {
cy.api_post(`/fields/contacts/${context}`, {
title: `automated test field contacts ${context}`,
access: 1,
context: `com_contact.${context}`,
default_value: '',
description: '',
group_id: 0,
label: 'contact field',
language: '*',
name: 'contact-field',
note: '',
params: {
class: '',
display: '2',
display_readonly: '2',
hint: '',
label_class: '',
label_render_class: '',
layout: '',
prefix: '',
render_class: '',
show_on: '',
showlabel: '1',
suffix: '',
},
required: 0,
state: 1,
type: 'text',
})
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test field contacts ${context}`));
});

it(`can update a field (${context})`, () => {
cy.db_createField({ title: 'automated test field', context: `com_contact.${context}` })
.then((id) => cy.api_patch(`/fields/contacts/${context}/${id}`, { title: `updated automated test field ${context}` }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `updated automated test field ${context}`));
});

it('can delete a field', () => {
cy.db_createField({ title: 'automated test field', state: -2 })
.then((id) => cy.api_delete(`/fields/contacts/contact/${id}`));
it(`can delete a field (${context})`, () => {
cy.db_createField({ title: 'automated test field', context: `com_contact.${context}`, state: -2 })
.then((id) => cy.api_delete(`/fields/contacts/${context}/${id}`));
});
});
});

0 comments on commit 4517709

Please sign in to comment.