diff --git a/tests/System/integration/api/com_contenthistory/Banner.cy.js b/tests/System/integration/api/com_contenthistory/Banner.cy.js new file mode 100644 index 0000000000000..0b887006c25c4 --- /dev/null +++ b/tests/System/integration/api/com_contenthistory/Banner.cy.js @@ -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}`); + }); + }); +}); diff --git a/tests/System/integration/api/com_contenthistory/Contact.cy.js b/tests/System/integration/api/com_contenthistory/Contact.cy.js new file mode 100644 index 0000000000000..3815e09ad06a9 --- /dev/null +++ b/tests/System/integration/api/com_contenthistory/Contact.cy.js @@ -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}`); + }); + }); +}); diff --git a/tests/System/integration/api/com_contenthistory/Content.cy.js b/tests/System/integration/api/com_contenthistory/Content.cy.js new file mode 100644 index 0000000000000..9f939f7b97119 --- /dev/null +++ b/tests/System/integration/api/com_contenthistory/Content.cy.js @@ -0,0 +1,114 @@ +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}`); + }); + }); + + it('can delete 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; + cy.api_delete(`/content/articles/${entry.id}/contenthistory`) + .then((result) => cy.wrap(result).its('status').should('equal', 204)); + }); + }); + }); +});