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

fix(tests): update history api tests to created ids #20199

Merged
merged 1 commit into from
Apr 24, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,25 @@ describeOnCondition(edition === 'EE')('History API', () => {
await localeService.create({ code: 'fr', name: 'French' });

// Create a collection type to create an initial history version
const collectionType = await createEntry({
const collectionTypeEntry = await createEntry({
uid: collectionTypeUid,
data: {
name: 'Product 1',
},
});

// Update the single type to create an initial history version
const singleType = await updateEntry({
const singleTypeEntry = await updateEntry({
uid: singleTypeUid,
data: {
title: 'Welcome',
},
isCollectionType: false,
});

// Set the documentIds to test
collectionTypeDocumentId = collectionType.data.documentId;
singleTypeDocumentId = singleType.data.documentId;
collectionTypeDocumentId = collectionTypeEntry.data.documentId;
singleTypeDocumentId = singleTypeEntry.data.documentId;

// Update to create history versions for entries in different locales
await Promise.all([
Expand All @@ -177,7 +178,7 @@ describeOnCondition(edition === 'EE')('History API', () => {
description: 'Hello',
},
}),
updateEntry({
await updateEntry({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await doesn't seem needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch I'll remove it in #20179

documentId: collectionTypeDocumentId,
uid: collectionTypeUid,
locale: 'fr',
Expand Down Expand Up @@ -356,10 +357,35 @@ describeOnCondition(edition === 'EE')('History API', () => {
});

describe('Restore a history version', () => {
let englishVersionIdToRestore;
let frenchVersionIdToRestore;

beforeAll(async () => {
// Set the entry ids to restore
englishVersionIdToRestore = (
await strapi.db.query('plugin::content-manager.history-version').findOne({
where: {
contentType: collectionTypeUid,
relatedDocumentId: collectionTypeDocumentId,
locale: 'en',
},
})
).id;
frenchVersionIdToRestore = (
await strapi.db.query('plugin::content-manager.history-version').findOne({
where: {
contentType: collectionTypeUid,
relatedDocumentId: collectionTypeDocumentId,
locale: 'fr',
},
})
).id;
});

test('Throws with invalid body', async () => {
const res = await rq({
method: 'PUT',
url: `/content-manager/history-versions/1/restore`,
url: `/content-manager/history-versions/${englishVersionIdToRestore}/restore`,
body: {},
});

Expand All @@ -380,7 +406,7 @@ describeOnCondition(edition === 'EE')('History API', () => {
]);
const res = await restrictedRq({
method: 'PUT',
url: `/content-manager/history-versions/1/restore`,
url: `/content-manager/history-versions/${englishVersionIdToRestore}/restore`,
body: {
contentType: collectionTypeUid,
},
Expand All @@ -404,7 +430,7 @@ describeOnCondition(edition === 'EE')('History API', () => {

await rq({
method: 'PUT',
url: `/content-manager/history-versions/1/restore`,
url: `/content-manager/history-versions/${englishVersionIdToRestore}/restore`,
body: {
contentType: collectionTypeUid,
},
Expand All @@ -425,7 +451,7 @@ describeOnCondition(edition === 'EE')('History API', () => {

await rq({
method: 'PUT',
url: `/content-manager/history-versions/4/restore`,
url: `/content-manager/history-versions/${frenchVersionIdToRestore}/restore`,
body: {
contentType: collectionTypeUid,
},
Expand Down
Loading