Skip to content

Commit

Permalink
fix bug in filePath with docx; updated test cases and gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
meddy672 committed Feb 5, 2024
1 parent 3ae41a9 commit 2a192eb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.env
node_modules
files
files/*.docx
dist
coverage
1 change: 1 addition & 0 deletions files/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quick fix for empty dir
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"test": "nyc jest --runInBand",
"stash": "git stash save 'stash changes'",
"case": "nyc jest --runInBand ./test/GPTDocx.test.ts",
"case": "nyc jest --runInBand ./test/acceptance.test.ts",
"format": "prettier --write --config .prettierrc.json src/**/*.{js,jsx,ts,tsx}",
"lint": "eslint ./src/**/*.ts",
"clean": "rimraf dist",
Expand Down
2 changes: 1 addition & 1 deletion src/Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WordDocument {
const arrayBuffer = await blob.arrayBuffer();
const file = Buffer.from(arrayBuffer);
writeFileSync(fileName, file);
return this._name + DOCUMENT.EXT;
return fileName;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/Document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe("Word Document", () =>{
expect(type).toEqual("string");
});
test('should trim the filename', () => {
expect(filename).toEqual("NewDocument.docx");
const { name, ext } = path.parse(filename);
expect(name+ext).toEqual("NewDocument.docx");
});
test('should call writeFileSync once with arguments', () => {
const spyArgs = writeFileSpy.mock.calls[0];
Expand Down
17 changes: 2 additions & 15 deletions test/DocxTemplater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("DocxTemplater", () => {
const filePath: any = new DocxTemplater({
docName: "A Paper About Whales",
service: "basic",
response: responseFormats["basicExample"],
response: responseFormats["basic"],
useAngularParser: false
}).create();
const { name, ext } = path.parse(filePath);
Expand All @@ -26,25 +26,12 @@ describe("DocxTemplater", () => {
const filePath: any = new DocxTemplater({
docName: "A Paper About Whales",
service: "basic",
response: responseFormats["basicExample"],
response: responseFormats["basic"],
useAngularParser: true
}).create();
const { name, ext } = path.parse(filePath);
expect(name).toEqual("APaperAboutWhales");
expect(ext).toEqual(".docx");
expect(fs.writeFileSync).toHaveBeenCalled();
});

// test("should return a filePath with a name and .docx extension when docName is undefined", () => {
// const filePath: any = new DocxTemplater({
// docName: undefined,
// service: "basicExample",
// response: responseFormats["basicExample"],
// useAngularParser: false
// }).create();
// const { name, ext } = path.parse(filePath);
// expect(name).toEqual("basicExample");
// expect(ext).toEqual(".docx");
// expect(fs.writeFileSync).toHaveBeenCalled();
// });
});
2 changes: 1 addition & 1 deletion test/GPTDocx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ describe("GPTDocx", () => {
let response: any;
try {
await new GPTDocx({
format: "basicExample",
format: "basic",
prompt: "",
}).createFile();
} catch (error: any) {
Expand Down
Loading

0 comments on commit 2a192eb

Please sign in to comment.