Skip to content

Commit 0dd2150

Browse files
alikonlaoneo
andauthored
[5.3] add com_contenthistory webservices endpoint test (#44666)
* com_contenthistory-api * cs * Use object destructuring prefer-destructuring * using object destructuring * delete-verb --------- Co-authored-by: Allon Moritz <[email protected]>
1 parent 41fea08 commit 0dd2150

File tree

3 files changed

+249
-0
lines changed

3 files changed

+249
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
describe('Test that contenthistory for banners API endpoint', () => {
2+
beforeEach(() => {
3+
cy.task('queryDB', 'DELETE FROM #__banners');
4+
cy.task('queryDB', 'DELETE FROM #__history');
5+
});
6+
7+
it('can get the history of an existing banner', () => {
8+
cy.db_createCategory({ extension: 'com_banners' })
9+
.then((categoryId) => cy.api_post('/banners', {
10+
name: 'automated test banner',
11+
alias: 'test-banner',
12+
catid: categoryId,
13+
state: 1,
14+
language: '*',
15+
description: '',
16+
custombannercode: '',
17+
params: {
18+
imageurl: '', width: '', height: '', alt: '',
19+
},
20+
}))
21+
.then((banner) => cy.api_get(`/banners/${banner.body.data.attributes.id}/contenthistory`))
22+
.then((response) => {
23+
// Assert response status
24+
expect(response.status).to.eq(200);
25+
26+
// Extract the `data` array
27+
const { data: historyEntries } = response.body;
28+
cy.log(`History Entries: ${historyEntries.length}`);
29+
30+
// Iterate through each history entry
31+
historyEntries.forEach((entry) => {
32+
const { attributes } = entry;
33+
34+
// Access top-level attributes
35+
const historyId = entry.id;
36+
const saveDate = attributes.save_date;
37+
const { editor } = attributes;
38+
const characterCount = attributes.character_count;
39+
40+
// Access nested `version_data`
41+
const versionData = attributes.version_data;
42+
const bannerName = versionData.name;
43+
const { alias } = versionData;
44+
const createdDate = versionData.created;
45+
const modifiedDate = versionData.modified;
46+
47+
// Log details for debugging
48+
cy.log(`History ID: ${historyId}`);
49+
cy.log(`Save Date: ${saveDate}`);
50+
cy.log(`Editor: ${editor}`);
51+
cy.log(`Character Count: ${characterCount}`);
52+
cy.log(`Banner Name: ${bannerName}`);
53+
cy.log(`Alias: ${alias}`);
54+
cy.log(`Created Date: ${createdDate}`);
55+
cy.log(`Modified Date: ${modifiedDate}`);
56+
57+
// Perform assertions
58+
expect(attributes).to.have.property('editor_user_id');
59+
expect(versionData).to.have.property('name');
60+
expect(versionData).to.have.property('modified');
61+
expect(bannerName).to.eq('automated test banner');
62+
});
63+
64+
// Check the total pages from metadata
65+
const totalPages = response.body.meta['total-pages'];
66+
expect(totalPages).to.eq(1);
67+
cy.log(`Total Pages: ${totalPages}`);
68+
});
69+
});
70+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
describe('Test that contenthistory for contact API endpoint', () => {
2+
beforeEach(() => {
3+
cy.task('queryDB', 'DELETE FROM #__contact_details');
4+
cy.task('queryDB', 'DELETE FROM #__history');
5+
});
6+
7+
it('can get the history of an existing contact', () => {
8+
cy.db_createCategory({ extension: 'com_contact' })
9+
.then((categoryId) => cy.api_post('/contacts', {
10+
name: 'automated test contact',
11+
alias: 'test-contact',
12+
catid: categoryId,
13+
published: 1,
14+
language: '*',
15+
}))
16+
.then((contact) => cy.api_get(`/contacts/${contact.body.data.attributes.id}/contenthistory`))
17+
.then((response) => {
18+
// Assert response status
19+
expect(response.status).to.eq(200);
20+
21+
// Extract the `data` array
22+
const { data: historyEntries } = response.body;
23+
cy.log(`History Entries: ${historyEntries.length}`);
24+
25+
// Iterate through each history entry
26+
historyEntries.forEach((entry) => {
27+
const { attributes } = entry;
28+
29+
// Access top-level attributes
30+
const historyId = entry.id;
31+
const saveDate = attributes.save_date;
32+
const { editor } = attributes;
33+
const characterCount = attributes.character_count;
34+
35+
// Access nested `version_data`
36+
const versionData = attributes.version_data;
37+
const contactName = versionData.name;
38+
const { alias } = versionData;
39+
const createdDate = versionData.created;
40+
const modifiedDate = versionData.modified;
41+
42+
// Log details for debugging
43+
cy.log(`History ID: ${historyId}`);
44+
cy.log(`Save Date: ${saveDate}`);
45+
cy.log(`Editor: ${editor}`);
46+
cy.log(`Character Count: ${characterCount}`);
47+
cy.log(`Contact Name: ${contactName}`);
48+
cy.log(`Alias: ${alias}`);
49+
cy.log(`Created Date: ${createdDate}`);
50+
cy.log(`Modified Date: ${modifiedDate}`);
51+
52+
// Perform assertions
53+
expect(attributes).to.have.property('editor_user_id');
54+
expect(versionData).to.have.property('name');
55+
expect(versionData).to.have.property('modified');
56+
expect(contactName).to.eq('automated test contact');
57+
});
58+
59+
// Check the total pages from metadata
60+
const totalPages = response.body.meta['total-pages'];
61+
expect(totalPages).to.eq(1);
62+
cy.log(`Total Pages: ${totalPages}`);
63+
});
64+
});
65+
});
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
describe('Test that contenthistory for content API endpoint', () => {
2+
beforeEach(() => {
3+
cy.task('queryDB', 'DELETE FROM #__content');
4+
cy.task('queryDB', 'DELETE FROM #__history');
5+
});
6+
7+
it('can get the history of an existing article', () => {
8+
cy.db_createCategory({ extension: 'com_content' })
9+
.then((categoryId) => cy.api_post('/content/articles', {
10+
title: 'automated test article',
11+
alias: 'test-article',
12+
catid: categoryId,
13+
introtext: '',
14+
fulltext: '',
15+
state: 1,
16+
access: 1,
17+
language: '*',
18+
created: '2023-01-01 20:00:00',
19+
modified: '2023-01-01 20:00:00',
20+
images: '',
21+
urls: '',
22+
attribs: '',
23+
metadesc: '',
24+
metadata: '',
25+
}))
26+
.then((article) => cy.api_get(`/content/articles/${article.body.data.attributes.id}/contenthistory`))
27+
.then((response) => {
28+
// Assert response status
29+
expect(response.status).to.eq(200);
30+
31+
// Extract the `data` array
32+
const { data: historyEntries } = response.body;
33+
cy.log(`History Entries: ${historyEntries.length}`);
34+
35+
// Iterate through each history entry
36+
historyEntries.forEach((entry) => {
37+
const { attributes } = entry;
38+
39+
// Access top-level attributes
40+
const historyId = entry.id;
41+
const saveDate = attributes.save_date;
42+
const { editor } = attributes;
43+
const characterCount = attributes.character_count;
44+
45+
// Access nested `version_data`
46+
const versionData = attributes.version_data;
47+
const articleTitle = versionData.title;
48+
const { alias } = versionData;
49+
const createdDate = versionData.created;
50+
const modifiedDate = versionData.modified;
51+
52+
// Log details for debugging
53+
cy.log(`History ID: ${historyId}`);
54+
cy.log(`Save Date: ${saveDate}`);
55+
cy.log(`Editor: ${editor}`);
56+
cy.log(`Character Count: ${characterCount}`);
57+
cy.log(`Article Title: ${articleTitle}`);
58+
cy.log(`Alias: ${alias}`);
59+
cy.log(`Created Date: ${createdDate}`);
60+
cy.log(`Modified Date: ${modifiedDate}`);
61+
62+
// Perform assertions
63+
expect(attributes).to.have.property('editor_user_id');
64+
expect(versionData).to.have.property('title');
65+
expect(versionData).to.have.property('modified');
66+
expect(articleTitle).to.eq('automated test article');
67+
});
68+
69+
// Check the total pages from metadata
70+
const totalPages = response.body.meta['total-pages'];
71+
expect(totalPages).to.eq(1);
72+
cy.log(`Total Pages: ${totalPages}`);
73+
});
74+
});
75+
76+
it('can delete the history of an existing article', () => {
77+
cy.db_createCategory({ extension: 'com_content' })
78+
.then((categoryId) => cy.api_post('/content/articles', {
79+
title: 'automated test article',
80+
alias: 'test-article',
81+
catid: categoryId,
82+
introtext: '',
83+
fulltext: '',
84+
state: 1,
85+
access: 1,
86+
language: '*',
87+
created: '2023-01-01 20:00:00',
88+
modified: '2023-01-01 20:00:00',
89+
images: '',
90+
urls: '',
91+
attribs: '',
92+
metadesc: '',
93+
metadata: '',
94+
}))
95+
.then((article) => cy.api_get(`/content/articles/${article.body.data.attributes.id}/contenthistory`))
96+
.then((response) => {
97+
// Assert response status
98+
expect(response.status).to.eq(200);
99+
// Extract the `data` array
100+
const { data: historyEntries } = response.body;
101+
cy.log(`History Entries: ${historyEntries.length}`);
102+
103+
// Iterate through each history entry
104+
historyEntries.forEach((entry) => {
105+
// const { attributes } = entry;
106+
107+
// Access top-level attributes
108+
// const historyId = entry.id;
109+
cy.api_delete(`/content/articles/${entry.id}/contenthistory`)
110+
.then((result) => cy.wrap(result).its('status').should('equal', 204));
111+
});
112+
});
113+
});
114+
});

0 commit comments

Comments
 (0)