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] Content category history endpoint #44670

Open
wants to merge 2 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
29 changes: 29 additions & 0 deletions plugins/webservices/content/src/Extension/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
$this->createFieldsRoutes($router);

$this->createContentHistoryRoutes($router);

$this->createContentCategoryHistoryRoutes($router);
}

/**
Expand Down Expand Up @@ -133,4 +135,31 @@ private function createContentHistoryRoutes(&$router): void

$router->addRoutes($routes);
}

/**
* Create content category history routes
*
* @param ApiRouter &$router The API Routing object
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
private function createContentCategoryHistoryRoutes(&$router): void
{
$defaults = [
'component' => 'com_contenthistory',
'type_alias' => 'com_content.category',
'type_id' => 5,
];
$getDefaults = array_merge(['public' => false], $defaults);

$routes = [
new Route(['GET'], 'v1/content/category/:id/contenthistory', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
new Route(['PATCH'], 'v1/content/category/:id/contenthistory/keep', 'history.keep', ['id' => '(\d+)'], $defaults),
new Route(['DELETE'], 'v1/content/category/:id/contenthistory', 'history.delete', ['id' => '(\d+)'], $defaults),
];

$router->addRoutes($routes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
describe('Test that contenthistory for content category API endpoint', () => {
beforeEach(() => {
cy.task('queryDB', "DELETE FROM #__categories WHERE title = 'automated test content category'");
cy.task('queryDB', 'DELETE FROM #__history');
});

it('can get the history of an existing article category', () => {
cy.api_post('/content/categories', { title: 'automated test content category', description: 'automated test content category description' })
.then((category) => cy.api_get(`/content/category/${category.body.data.attributes.id}/contenthistory`))
.then((response) => {
// Assert response status
expect(response.status).to.eq(200);

// Extract the `data` array
const historyEntries = response.body.data;
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 categoryTitle = versionData.title;
const { alias } = versionData;
const createdTime = versionData.created_time;
const modifiedTime = versionData.modified_time;

// 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(`Category Title: ${categoryTitle}`);
cy.log(`Alias: ${alias}`);
cy.log(`Created Time: ${createdTime}`);
cy.log(`Modified Time: ${modifiedTime}`);

// Perform assertions
expect(attributes).to.have.property('editor_user_id');
expect(versionData).to.have.property('title');
expect(versionData).to.have.property('modified_time');
expect(categoryTitle).to.eq('automated test content category');
});

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