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] Tag history endpoint #44669

Open
wants to merge 3 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
30 changes: 30 additions & 0 deletions plugins/webservices/tags/src/Extension/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Event\Application\BeforeApiRouteEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\SubscriberInterface;
use Joomla\Router\Route;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -57,5 +58,34 @@ public function onBeforeApiRoute(BeforeApiRouteEvent $event): void
'tags',
['component' => 'com_tags']
);

$this->createTagHistoryRoutes($router);
}

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

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

$router->addRoutes($routes);
}
}
60 changes: 60 additions & 0 deletions tests/System/integration/api/com_contenthistory/Tag.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe('Test that contenthistory for tag API endpoint', () => {
beforeEach(() => {
cy.task('queryDB', "DELETE FROM #__tags where title = 'automated test tag'");
cy.task('queryDB', 'DELETE FROM #__history');
});

it('can get the history of an existing tag', () => {
cy.api_post('/tags', {
title: 'automated test tag', parent_id: 1, level: 1, description: '', language: '*',
})
.then((tag) => cy.api_get(`/tags/${tag.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 tagTitle = 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(`Tag Title: ${tagTitle}`);
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(tagTitle).to.eq('automated test tag');
});

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