Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] add com_contenthistory webservices endpoint test #44666

Open
wants to merge 5 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions tests/System/integration/api/com_contenthistory/Banner.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
describe('Test that contenthistory for banners API endpoint', () => {
beforeEach(() => {
cy.task('queryDB', 'DELETE FROM #__banners');
cy.task('queryDB', 'DELETE FROM #__history');
});

it('can get the history of an existing banner', () => {
cy.db_createCategory({ extension: 'com_banners' })
.then((categoryId) => cy.api_post('/banners', {
name: 'automated test banner',
alias: 'test-banner',
catid: categoryId,
state: 1,
language: '*',
description: '',
custombannercode: '',
params: {
imageurl: '', width: '', height: '', alt: '',
},
}))
.then((banner) => cy.api_get(`/banners/${banner.body.data.attributes.id}/contenthistory`))
.then((response) => {
// Assert response status
expect(response.status).to.eq(200);

// Extract the `data` array
const { data: historyEntries } = response.body;
cy.log(`History Entries: ${historyEntries.length}`);

// Iterate through each history entry
historyEntries.forEach((entry) => {
const { attributes } = entry;

// Access top-level attributes
const historyId = entry.id;
const saveDate = attributes.save_date;
const { editor } = attributes;
const characterCount = attributes.character_count;

// Access nested `version_data`
const versionData = attributes.version_data;
const bannerName = versionData.name;
const { alias } = versionData;
const createdDate = versionData.created;
const modifiedDate = versionData.modified;

// Log details for debugging
cy.log(`History ID: ${historyId}`);
cy.log(`Save Date: ${saveDate}`);
cy.log(`Editor: ${editor}`);
cy.log(`Character Count: ${characterCount}`);
cy.log(`Banner Name: ${bannerName}`);
cy.log(`Alias: ${alias}`);
cy.log(`Created Date: ${createdDate}`);
cy.log(`Modified Date: ${modifiedDate}`);

// Perform assertions
expect(attributes).to.have.property('editor_user_id');
expect(versionData).to.have.property('name');
expect(versionData).to.have.property('modified');
expect(bannerName).to.eq('automated test banner');
});

// Check the total pages from metadata
const totalPages = response.body.meta['total-pages'];
expect(totalPages).to.eq(1);
cy.log(`Total Pages: ${totalPages}`);
});
});
});
65 changes: 65 additions & 0 deletions tests/System/integration/api/com_contenthistory/Contact.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
describe('Test that contenthistory for contact API endpoint', () => {
beforeEach(() => {
cy.task('queryDB', 'DELETE FROM #__contact_details');
cy.task('queryDB', 'DELETE FROM #__history');
});

it('can get the history of an existing contact', () => {
cy.db_createCategory({ extension: 'com_contact' })
.then((categoryId) => cy.api_post('/contacts', {
name: 'automated test contact',
alias: 'test-contact',
catid: categoryId,
published: 1,
language: '*',
}))
.then((contact) => cy.api_get(`/contacts/${contact.body.data.attributes.id}/contenthistory`))
.then((response) => {
// Assert response status
expect(response.status).to.eq(200);

// Extract the `data` array
const { data: historyEntries } = response.body;
cy.log(`History Entries: ${historyEntries.length}`);

// Iterate through each history entry
historyEntries.forEach((entry) => {
const { attributes } = entry;

// Access top-level attributes
const historyId = entry.id;
const saveDate = attributes.save_date;
const { editor } = attributes;
const characterCount = attributes.character_count;

// Access nested `version_data`
const versionData = attributes.version_data;
const contactName = versionData.name;
const { alias } = versionData;
const createdDate = versionData.created;
const modifiedDate = versionData.modified;

// Log details for debugging
cy.log(`History ID: ${historyId}`);
cy.log(`Save Date: ${saveDate}`);
cy.log(`Editor: ${editor}`);
cy.log(`Character Count: ${characterCount}`);
cy.log(`Contact Name: ${contactName}`);
cy.log(`Alias: ${alias}`);
cy.log(`Created Date: ${createdDate}`);
cy.log(`Modified Date: ${modifiedDate}`);

// Perform assertions
expect(attributes).to.have.property('editor_user_id');
expect(versionData).to.have.property('name');
expect(versionData).to.have.property('modified');
expect(contactName).to.eq('automated test contact');
});

// Check the total pages from metadata
const totalPages = response.body.meta['total-pages'];
expect(totalPages).to.eq(1);
cy.log(`Total Pages: ${totalPages}`);
});
});
});
75 changes: 75 additions & 0 deletions tests/System/integration/api/com_contenthistory/Content.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
describe('Test that contenthistory for content API endpoint', () => {
beforeEach(() => {
cy.task('queryDB', 'DELETE FROM #__content');
cy.task('queryDB', 'DELETE FROM #__history');
});

it('can get the history of an existing article', () => {
cy.db_createCategory({ extension: 'com_content' })
.then((categoryId) => cy.api_post('/content/articles', {
title: 'automated test article',
alias: 'test-article',
catid: categoryId,
introtext: '',
fulltext: '',
state: 1,
access: 1,
language: '*',
created: '2023-01-01 20:00:00',
modified: '2023-01-01 20:00:00',
images: '',
urls: '',
attribs: '',
metadesc: '',
metadata: '',
}))
.then((article) => cy.api_get(`/content/articles/${article.body.data.attributes.id}/contenthistory`))
.then((response) => {
// Assert response status
expect(response.status).to.eq(200);

// Extract the `data` array
const { data: historyEntries } = response.body;
cy.log(`History Entries: ${historyEntries.length}`);

// Iterate through each history entry
historyEntries.forEach((entry) => {
const { attributes } = entry;

// Access top-level attributes
const historyId = entry.id;
const saveDate = attributes.save_date;
const { editor } = attributes;
const characterCount = attributes.character_count;

// Access nested `version_data`
const versionData = attributes.version_data;
const articleTitle = versionData.title;
const { alias } = versionData;
const createdDate = versionData.created;
const modifiedDate = versionData.modified;

// Log details for debugging
cy.log(`History ID: ${historyId}`);
cy.log(`Save Date: ${saveDate}`);
cy.log(`Editor: ${editor}`);
cy.log(`Character Count: ${characterCount}`);
cy.log(`Article Title: ${articleTitle}`);
cy.log(`Alias: ${alias}`);
cy.log(`Created Date: ${createdDate}`);
cy.log(`Modified Date: ${modifiedDate}`);

// Perform assertions
expect(attributes).to.have.property('editor_user_id');
expect(versionData).to.have.property('title');
expect(versionData).to.have.property('modified');
expect(articleTitle).to.eq('automated test article');
});

// Check the total pages from metadata
const totalPages = response.body.meta['total-pages'];
expect(totalPages).to.eq(1);
cy.log(`Total Pages: ${totalPages}`);
});
});
});