fix: duplicate with relationships

This commit is contained in:
Dan Ribbens
2022-09-16 12:26:18 -04:00
parent 4be14a12d0
commit eabb981243
2 changed files with 19 additions and 4 deletions

View File

@@ -32,9 +32,11 @@ const Duplicate: React.FC<Props> = ({ slug, collection, id }) => {
return; return;
} }
const create = async (locale?: string): Promise<string | null> => { const create = async (locale = ''): Promise<string | null> => {
const localeParam = locale ? `locale=${locale}` : ''; const response = await requests.get(`${serverURL}${api}/${slug}/${id}`, {
const response = await requests.get(`${serverURL}${api}/${slug}/${id}?${localeParam}`); locale,
depth: 0,
});
const data = await response.json(); const data = await response.json();
const result = await requests.post(`${serverURL}${api}/${slug}`, { const result = await requests.post(`${serverURL}${api}/${slug}`, {
headers: { headers: {
@@ -59,7 +61,10 @@ const Duplicate: React.FC<Props> = ({ slug, collection, id }) => {
.filter((locale) => locale !== localization.defaultLocale) .filter((locale) => locale !== localization.defaultLocale)
.forEach(async (locale) => { .forEach(async (locale) => {
if (!abort) { if (!abort) {
const res = await requests.get(`${serverURL}${api}/${slug}/${id}?locale=${locale}`); const res = await requests.get(`${serverURL}${api}/${slug}/${id}`, {
locale,
depth: 0,
});
const localizedDoc = await res.json(); const localizedDoc = await res.json();
const patchResult = await requests.patch(`${serverURL}${api}/${slug}/${duplicateID}?locale=${locale}`, { const patchResult = await requests.patch(`${serverURL}${api}/${slug}/${duplicateID}?locale=${locale}`, {
headers: { headers: {

View File

@@ -169,6 +169,16 @@ describe('fields - relationship', () => {
await saveDocAndAssert(page); await saveDocAndAssert(page);
}); });
test('should duplicate document with relationships', async () => {
await page.goto(url.edit(docWithExistingRelations.id));
await page.locator('.btn.duplicate').first().click();
await expect(page.locator('.Toastify')).toContainText('successfully');
const field = page.locator('#field-relationship .rs__value-container');
await expect(field).toHaveText(relationOneDoc.id);
});
describe('existing relationships', () => { describe('existing relationships', () => {
test('should highlight existing relationship', async () => { test('should highlight existing relationship', async () => {
await page.goto(url.edit(docWithExistingRelations.id)); await page.goto(url.edit(docWithExistingRelations.id));