Skip to content

Commit

Permalink
ADD: Test is passing! ...but breaks the other tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsrogil committed Feb 26, 2024
1 parent 579d7a8 commit 099e91d
Showing 1 changed file with 115 additions and 1 deletion.
116 changes: 115 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,108 @@ describe('@apostrophecms/import-export', function () {
await cleanFile(exportPath);
});

it.only('should preserve lastPublishedAt property on import for existing drafts', async function() {
console.log('[TEST] should preserve lastPublishedAt property on import for existing drafts');

// Get the page2 that was meant for testing
const req = apos.task.getReq();
const page2 = await apos.page.find(req, { title: 'page2' }).toObject();

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Trailing spaces not allowed

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Trailing spaces not allowed

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Trailing spaces not allowed

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Trailing spaces not allowed

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Trailing spaces not allowed

Check failure on line 229 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Trailing spaces not allowed
// PUBLISH IT
const publishedResult = await apos.page.publish(req, page2);

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 231 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

'publishedResult' is assigned a value but never used. Allowed unused vars must match /apos/u
// THEN UNPUBLISH IT
const draftPage = await apos.page.unpublish(req, page2);

// THEN EXPORT IT (as draft)
req.body = {
_ids: [ draftPage._id ],
extension: 'gzip',
type: draftPage.type
};

const { url } = await importExportManager.export(req, apos.page);
const fileName = path.basename(url);

pageTgzPath = path.join(exportsPath, fileName);
const exportPath = await gzip.input(pageTgzPath);

const { docs } = await getExtractedFiles(exportPath);
const exportedDraftPage = docs.find(doc => doc._id === draftPage._id);

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 249 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

'exportedDraftPage' is assigned a value but never used. Allowed unused vars must match /apos/u

console.log('docs (exported) >>>', docs);

// @TODO Delete:
// Test exported doc

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Trailing spaces not allowed

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Trailing spaces not allowed

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Trailing spaces not allowed

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Trailing spaces not allowed

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Trailing spaces not allowed

Check failure on line 254 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Trailing spaces not allowed
const exportedDoc = await apos.doc.db

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u

Check failure on line 255 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

'exportedDoc' is assigned a value but never used. Allowed unused vars must match /apos/u
.find({ type: /default-page|article|topic|@apostrophecms\/image/, title: 'page2' })

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected a line break before this closing brace

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected a line break before this closing brace

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected a line break before this closing brace

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected a line break before this closing brace

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected a line break before this closing brace

Check failure on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected indentation of 6 spaces but found 4

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected a line break after this opening brace

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Object properties must go on a new line

Check warning on line 256 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected a line break before this closing brace
.toArray();

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected indentation of 6 spaces but found 4

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 257 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected indentation of 6 spaces but found 4
// Last published at est bien à "null" et c'est bien un draft

// Seems it correctly exported
// Now we PUBLISH it
const result = await apos.page.publish(req, draftPage);
console.log({ result });

const updatedPage2 = await apos.doc.db
.find({ title: 'page2', aposMode: 'published' })

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected a line break before this closing brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected a line break before this closing brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected a line break before this closing brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected a line break before this closing brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected a line break before this closing brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected a line break after this opening brace

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Object properties must go on a new line

Check warning on line 266 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected a line break before this closing brace
.toArray();
console.log(updatedPage2);

// Rename tar file for import issue
const currentPath = pageTgzPath;
const newPath = currentPath.replace('.tar.gz', '-import.tar.gz');
try {
await fs.rename(currentPath, newPath);
console.log(`Fichier renommé de ${currentPath} à ${newPath}`);
} catch (error) {
console.error('Erreur lors du renommage du fichier :', error);
}

console.log('Then import it');

// IMPORT IT
req.body = {};
req.files = {
file: {
path: newPath,
type: mimeType
}
};

const {
duplicatedDocs,
importedAttachments,
exportPathId,
jobId,
notificationId
} = await importExportManager.import(req);

req.body = {
docIds: duplicatedDocs.map(doc => doc.aposDocId),
importedAttachments,
exportPathId,
jobId,
notificationId
}

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Missing semicolon

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Missing semicolon

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Missing semicolon

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Missing semicolon

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Missing semicolon

Check failure on line 305 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Missing semicolon

await importExportManager.overrideDuplicates(req);

const NewUpdatedPage2 = await apos.doc.db
.find({ title: 'page2' })

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected indentation of 6 spaces but found 4

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 310 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected indentation of 6 spaces but found 4
.toArray();

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 4.4)

Expected indentation of 6 spaces but found 4

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (16, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 5.0)

Expected indentation of 6 spaces but found 4

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (20, 6.0)

Expected indentation of 6 spaces but found 4

Check failure on line 311 in test/index.js

View workflow job for this annotation

GitHub Actions / build (18, 6.0)

Expected indentation of 6 spaces but found 4
console.log('NewUpdatedPage2 >>>', NewUpdatedPage2);

// Check that the imported docs are not `null`

assert.deepEqual(NewUpdatedPage2.some((doc) => {
console.log('doc.lastPublishedAt > ', doc.lastPublishedAt)
return doc.lastPublishedAt === null;
}), false, 'expected none of the imported docs to have a `lastPublishedAt` value of `null`');

// @TODO: Cleanup
// ...
});

it('should import pieces with related documents from a compressed file', async function() {
const req = apos.task.getReq();

Expand Down Expand Up @@ -1410,7 +1512,19 @@ async function insertPieces(apos) {
}
],
metaType: 'area'
}
},
});

await apos.page.insert(req, '_home', 'lastChild', {
...pageInstance,
title: 'page2',
type: 'default-page',
_articles: [],
main: {
_id: 'areaId',
items: [],
metaType: 'area'
},
});
}

Expand Down

0 comments on commit 099e91d

Please sign in to comment.