diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-26 18:16:50 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-26 18:16:50 +0000 |
| commit | f5fbc6e4aface5c6c9537b38d1650b0d37e3cbc1 (patch) | |
| tree | 00dc33ece5cd79b72af7889dfb748e661104ab33 | |
| parent | 818cedc5fd9e83a633df5fae5c341996abcd9e80 (diff) | |
Add tests for findPartPaths
| -rw-r--r-- | lib/docx/docx-reader.js | 1 | ||||
| -rw-r--r-- | test/docx/docx-reader.tests.js | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index ac021b9..beade38 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -1,4 +1,5 @@ exports.read = read; +exports._findPartPaths = findPartPaths; var path = require("path"); diff --git a/test/docx/docx-reader.tests.js b/test/docx/docx-reader.tests.js index 26f06ac..0556405 100644 --- a/test/docx/docx-reader.tests.js +++ b/test/docx/docx-reader.tests.js @@ -86,3 +86,32 @@ test("error is thrown when main document part does not exist", function() { assert.equal(error.message, "Could not find main document part. Are you sure this is a valid .docx file?"); }); }); + + +test("part paths", { + "main document part is found using package relationships": function() { + var relationships = xml.element("r:Relationships", {}, [ + xml.element("r:Relationship", { + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument", + "Target": "/word/document2.xml" + }) + ]); + + var docxFile = createFakeDocxFile({ + "word/document2.xml": " ", + "_rels/.rels": xml.writeString(relationships, relationshipNamespaces) + }); + return docxReader._findPartPaths(docxFile).then(function(partPaths) { + assert.equal(partPaths.mainDocument, "word/document2.xml"); + }); + }, + + "word/document.xml is used as fallback location for main document part": function() { + var docxFile = createFakeDocxFile({ + "word/document.xml": " " + }); + return docxReader._findPartPaths(docxFile).then(function(partPaths) { + assert.equal(partPaths.mainDocument, "word/document.xml"); + }); + } +}); |
