Skip to content

Commit

Permalink
[4.4] api tests content (#41311)
Browse files Browse the repository at this point in the history
  • Loading branch information
heelc29 committed Aug 9, 2023
1 parent 0df0715 commit cad188c
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 106 deletions.
8 changes: 8 additions & 0 deletions tests/System/integration/api/com_content/Articles.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ describe('Test that content API endpoint', () => {
.should('include', 'automated test article'));
});

it('can deliver a single article', () => {
cy.db_createArticle({ title: 'automated test article' })
.then((article) => cy.api_get(`/content/articles/${article.id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'automated test article'));
});

it('can create an article', () => {
cy.db_createCategory({ extension: 'com_content' })
.then((categoryId) => cy.api_post('/content/articles', {
Expand Down
29 changes: 27 additions & 2 deletions tests/System/integration/api/com_content/Categories.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
describe('Test that content categories API endpoint', () => {
afterEach(() => cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'automated test content category'"));

it('can display a list of categories', () => {
cy.db_createCategory({ title: 'automated test category', extension: 'com_content' })
cy.db_createCategory({ title: 'automated test content category', extension: 'com_content' })
.then((id) => cy.db_createArticle({ title: 'automated test article', catid: id }))
.then(() => cy.api_get('/content/categories'))
.then((response) => cy.api_responseContains(response, 'title', 'automated test category'));
.then((response) => cy.api_responseContains(response, 'title', 'automated test content category'));
});

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

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

it('can update a category', () => {
cy.db_createCategory({ title: 'automated test content category', extension: 'com_content' })
.then((id) => cy.api_patch(`/content/categories/${id}`, { title: 'updated automated test content category' }))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', 'updated automated test content category'));
});
});
115 changes: 63 additions & 52 deletions tests/System/integration/api/com_content/Field_Group.cy.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,70 @@
describe('Test that group field article API endpoint', () => {
describe('Test that group field content API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__fields_groups'));

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

it('can create a group field', () => {
cy.api_post('/fields/groups/content/articles', {
title: 'automated test group field',
access: 1,
context: 'com_content.article',
default_value: '',
description: '',
group_id: 0,
label: 'content group field',
language: '*',
name: 'content-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 content ${context}`, context: `com_content.${context}` })
.then((id) => cy.api_get(`/fields/groups/content/${endpoint}/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test group field content ${context}`));
});

it('can update a group field', () => {
cy.db_createFieldGroup({ title: 'automated test field group', access: 1, context: 'com_content.article' })
.then((id) => cy.api_patch(`/fields/groups/content/articles/${id}`, { title: 'updated automated test group field', context: 'com_content.article' }))
.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/content/${endpoint}`, {
title: `automated test group field content ${context}`,
access: 1,
context: `com_content.${context}`,
default_value: '',
description: '',
group_id: 0,
label: 'content group field',
language: '*',
name: 'content-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 content ${context}`));
});

it(`can update a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', access: 1, context: `com_content.${context}` })
.then((id) => cy.api_patch(`/fields/groups/content/${endpoint}/${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/content/articles/${id}`));
it(`can delete a group field (${context})`, () => {
cy.db_createFieldGroup({ title: 'automated test group field', context: `com_content.${context}`, state: -2 })
.then((id) => cy.api_delete(`/fields/groups/content/${endpoint}/${id}`));
});
});
});
115 changes: 63 additions & 52 deletions tests/System/integration/api/com_content/Fields.cy.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,70 @@
describe('Test that field article API endpoint', () => {
describe('Test that field content API endpoint', () => {
afterEach(() => cy.task('queryDB', 'DELETE FROM #__fields'));

it('can deliver a list of fields', () => {
cy.db_createField({ title: 'automated test field' })
.then(() => cy.api_get('/fields/content/articles'))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', 'automated test field'));
});
['article', 'categories'].forEach((context) => {
const endpoint = context === 'article' ? 'articles' : context;
it(`can deliver a list of fields (${context})`, () => {
cy.db_createField({ title: `automated test field content ${context}`, context: `com_content.${context}` })
.then(() => cy.api_get(`/fields/content/${endpoint}`))
.then((response) => cy.wrap(response).its('body').its('data.0').its('attributes')
.its('title')
.should('include', `automated test field content ${context}`));
});

it('can create a field', () => {
cy.api_post('/fields/content/articles', {
title: 'automated test field',
access: 1,
context: 'com_content.article',
default_value: '',
description: '',
group_id: 0,
label: 'content field',
language: '*',
name: 'content-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 content ${context}`, context: `com_content.${context}` })
.then((id) => cy.api_get(`/fields/content/${endpoint}/${id}`))
.then((response) => cy.wrap(response).its('body').its('data').its('attributes')
.its('title')
.should('include', `automated test field content ${context}`));
});

it('can update a field', () => {
cy.db_createField({ title: 'automated test field', access: 1 })
.then((id) => cy.api_patch(`/fields/content/articles/${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/content/${endpoint}`, {
title: `automated test field content ${context}`,
access: 1,
context: `com_content.${context}`,
default_value: '',
description: '',
group_id: 0,
label: 'content field',
language: '*',
name: `content-field-${context}`,
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 content ${context}`));
});

it(`can update a field (${context})`, () => {
cy.db_createField({ title: 'automated test field', context: `com_content.${context}`, access: 1 })
.then((id) => cy.api_patch(`/fields/content/${endpoint}/${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/content/articles/${id}`));
it(`can delete a field (${context})`, () => {
cy.db_createField({ title: 'automated test field', context: `com_content.${context}`, state: -2 })
.then((id) => cy.api_delete(`/fields/content/${endpoint}/${id}`));
});
});
});

0 comments on commit cad188c

Please sign in to comment.