Commit bfe5d42b authored by Robert Knight's avatar Robert Knight

Refactor `getMetadata` tests

 - Convert promise chains to async/await

 - Add missing tests to check that the PDF URL and fingerprint URL
   appear in the object returned by `getMetadata`. These were previously
   tested indirectly in other tests.

 - Change tests to only check the specific properties of the returned
   object that are of interest. This reduces the changes needed when
   tests change unrelated parts of the output.
parent 1b539b87
......@@ -208,7 +208,6 @@ describe('PDFMetadata', function () {
});
});
describe('metadata sources', function () {
const testMetadata = {
fingerprint: 'fakeFingerprint',
title: 'fakeTitle',
......@@ -262,69 +261,58 @@ describe('PDFMetadata', function () {
});
});
describe('#getMetadata', function () {
it('gets the title from the dc:title field', function () {
const { fakePDFViewerApplication, pdfMetadata } = createPDFMetadata();
const expectedMetadata = {
title: 'dcFakeTitle',
link: [
{
href:
'urn:x-pdf:' + fakePDFViewerApplication.pdfDocument.fingerprint,
},
{ href: fakePDFViewerApplication.url },
],
documentFingerprint: fakePDFViewerApplication.pdfDocument.fingerprint,
};
describe('#getMetadata', () => {
it('returns the document fingerprint in the `documentFingerprint` property', async () => {
const { pdfMetadata } = createPDFMetadata();
const metadata = await pdfMetadata.getMetadata();
assert.equal(metadata.documentFingerprint, testMetadata.fingerprint);
});
return pdfMetadata.getMetadata().then(function (actualMetadata) {
assert.deepEqual(actualMetadata, expectedMetadata);
it('returns the PDF URL in the `links` array', async () => {
const { pdfMetadata } = createPDFMetadata();
const metadata = await pdfMetadata.getMetadata();
assert.deepInclude(metadata.link, {
href: testMetadata.url,
});
});
it('gets the title from the documentInfo.Title field', function () {
const { fakePDFViewerApplication, pdfMetadata } = createPDFMetadata();
const expectedMetadata = {
title: fakePDFViewerApplication.documentInfo.Title,
link: [
{
href:
'urn:x-pdf:' + fakePDFViewerApplication.pdfDocument.fingerprint,
},
{ href: fakePDFViewerApplication.url },
],
documentFingerprint: fakePDFViewerApplication.pdfDocument.fingerprint,
};
fakePDFViewerApplication.metadata.has = sinon.stub().returns(false);
return pdfMetadata.getMetadata().then(function (actualMetadata) {
assert.deepEqual(actualMetadata, expectedMetadata);
it('returns the document fingerprint in the `links` array', async () => {
const { pdfMetadata } = createPDFMetadata();
const metadata = await pdfMetadata.getMetadata();
assert.deepInclude(metadata.link, {
href: `urn:x-pdf:${testMetadata.fingerprint}`,
});
});
it('does not save file:// URLs in document metadata', function () {
const { fakePDFViewerApplication, pdfMetadata } = createPDFMetadata({
it('does not return file:// URLs in `links` array', async () => {
const { pdfMetadata } = createPDFMetadata({
fingerprint: 'fakeFingerprint',
url: 'file://fake.pdf',
});
const expectedMetadata = {
link: [
{
href:
'urn:x-pdf:' + fakePDFViewerApplication.pdfDocument.fingerprint,
},
],
};
return pdfMetadata.getMetadata().then(function (actualMetadata) {
assert.equal(actualMetadata.link.length, 1);
assert.equal(
actualMetadata.link[0].href,
expectedMetadata.link[0].href
const metadata = await pdfMetadata.getMetadata();
const fileLink = metadata.link.find(link =>
link.href.includes('file://')
);
assert.isUndefined(fileLink);
});
it('gets the title from the dc:title field', async () => {
const { pdfMetadata } = createPDFMetadata();
const metadata = await pdfMetadata.getMetadata();
assert.equal(metadata.title, testMetadata.metadata['dc:title']);
});
it('gets the title from the documentInfo.Title field', async () => {
const { pdfMetadata } = createPDFMetadata({
title: 'Some title',
url: 'http://fake.com/',
});
const metadata = await pdfMetadata.getMetadata();
assert.equal(metadata.title, 'Some title');
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment