From a8631424386e43ad95e1878dff36f5e9469cc7c0 Mon Sep 17 00:00:00 2001 From: Fahim Date: Mon, 17 Aug 2020 21:07:43 +0530 Subject: [PATCH 1/8] tests: Meta tests fix --- src/meta/frappe.meta.controller.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta/frappe.meta.controller.spec.ts b/src/meta/frappe.meta.controller.spec.ts index 6d9cada..45e4a6d 100644 --- a/src/meta/frappe.meta.controller.spec.ts +++ b/src/meta/frappe.meta.controller.spec.ts @@ -11,7 +11,7 @@ describe("Frappe Meta Controller", function() { const validUser = TestManager.primaryUser; const validPwd = TestManager.primaryUserPwd; - const testDoctype = "Renovation Review"; + const testDoctype = "Renovation Dashboard"; this.timeout(10000); From 52fa7b31acd7ecdaf951c4cc0484956c8aefbd7a Mon Sep 17 00:00:00 2001 From: Fahim Date: Mon, 17 Aug 2020 21:17:24 +0530 Subject: [PATCH 2/8] tests: updated test titles --- src/meta/frappe.meta.controller.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/meta/frappe.meta.controller.spec.ts b/src/meta/frappe.meta.controller.spec.ts index 45e4a6d..5d36159 100644 --- a/src/meta/frappe.meta.controller.spec.ts +++ b/src/meta/frappe.meta.controller.spec.ts @@ -77,7 +77,7 @@ describe("Frappe Meta Controller", function() { }); describe("getDocMeta", function() { - it("should return DocType Obj for Renovation Review", async function() { + it(`should return DocType Obj for ${testDoctype}`, async function() { const docResponse = await renovation.meta.getDocMeta({ doctype: testDoctype }); @@ -86,14 +86,14 @@ describe("Frappe Meta Controller", function() { expect(docResponse.data.fields).length.gte(0); }); - it("should return DocType Obj for Renovation Review [deprecated]", async function() { + it(`should return DocType Obj for ${testDoctype} [deprecated]`, async function() { const docResponse = await renovation.meta.getDocMeta(testDoctype); expect(docResponse.data.doctype).equals(testDoctype); expect(docResponse.data.fields).length.gte(0); }); - it("should return DocType Obj for Renovation Review [deprecated]", async function() { + it(`should return DocType Obj for ${testDoctype} [deprecated]`, async function() { const docResponse = await renovation.meta.loadDocType(testDoctype); expect(docResponse.data.doctype).equals(testDoctype); From 71ad96cf2e69388b25be646794aa8422bdc52fc6 Mon Sep 17 00:00:00 2001 From: Fahim Date: Mon, 17 Aug 2020 21:23:08 +0530 Subject: [PATCH 3/8] tests: meta.controller.spec.ts updates --- src/meta/meta.controller.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meta/meta.controller.spec.ts b/src/meta/meta.controller.spec.ts index f55709e..d379e3b 100644 --- a/src/meta/meta.controller.spec.ts +++ b/src/meta/meta.controller.spec.ts @@ -13,7 +13,7 @@ describe("Meta Controller", function() { const validUser = TestManager.primaryUser; const validPwd = TestManager.primaryUserPwd; - const testDoctype = "Renovation Review"; + const testDoctype = "Blogger"; before(async function() { this.timeout(10000); @@ -40,16 +40,16 @@ describe("Meta Controller", function() { }) ); - it("should get the field label of reviewed_by of doctype Renovation Review", async function() { + it(`should get the field label of short_name of doctype ${testDoctype}`, async function() { const fieldLabel = await renovation.meta.getFieldLabel({ doctype: testDoctype, - fieldname: "reviewed_by" + fieldname: "short_name" }); - expect(fieldLabel).to.be.equal("Reviewed By"); + expect(fieldLabel).to.be.equal("Short Name"); }); - it("should get the standard field for doctype Renovation Review", async function() { + it(`should get the standard field for doctype ${testDoctype}`, async function() { const fieldLabel = await renovation.meta.getFieldLabel({ doctype: testDoctype, fieldname: "name" From 61b0e1fa02008ce1c4e2353f439151ca03475c44 Mon Sep 17 00:00:00 2001 From: Fahim Date: Mon, 17 Aug 2020 21:52:16 +0530 Subject: [PATCH 4/8] tests: model.controller.spec.ts --- src/model/model.controller.spec.ts | 106 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/model/model.controller.spec.ts b/src/model/model.controller.spec.ts index f11581c..ecd58af 100644 --- a/src/model/model.controller.spec.ts +++ b/src/model/model.controller.spec.ts @@ -11,7 +11,7 @@ describe("ModelController", function() { const validUser = TestManager.primaryUser; const validPwd = TestManager.primaryUserPwd; - const testDoctype = "Renovation User Agreement"; + const testDoctype = "Blogger"; before(async function() { renovation = await TestManager.init("frappe"); @@ -30,7 +30,7 @@ describe("ModelController", function() { describe("newDoc", function() { it("should create a new RenovationDocument", async function() { const newDoc = await renovation.model.newDoc({ - doctype: "Renovation User Agreement" + doctype: testDoctype }); expect(newDoc.doctype).to.be.equal(testDoctype); expect(newDoc.name).to.be.equal(`New ${testDoctype} 1`); @@ -43,7 +43,7 @@ describe("ModelController", function() { }); it("should create a new RenovationDocument [deprecated]", async function() { - const newDoc = await renovation.model.newDoc("Renovation User Agreement"); + const newDoc = await renovation.model.newDoc(testDoctype); expect(newDoc.doctype).to.be.equal(testDoctype); expect(newDoc.name).to.be.equal(`New ${testDoctype} 1`); expect(newDoc.docstatus).to.be.equal(0); @@ -158,93 +158,93 @@ describe("ModelController", function() { }); it("should successfully get child doc when it's not defined in the input RenovationDocument", async function() { const newDoc = await renovation.model.newDoc({ - doctype: "Renovation Review" + doctype: "User" }); const childDoc = await renovation.model.addChildDoc({ doc: newDoc, - field: "reviews" + field: "roles" }); - expect(childDoc.parent).to.be.equal("New Renovation Review 1"); - expect(childDoc.parenttype).to.be.equal("Renovation Review"); + expect(childDoc.parent).to.be.equal("New User 1"); + expect(childDoc.parenttype).to.be.equal("User"); expect(childDoc.idx).to.be.equal(1); - expect(newDoc.reviews).to.be.a("Array"); - expect(newDoc.reviews.length).to.be.equal(1); - expect(newDoc.reviews[0].name).to.be.equal( - "New Renovation Review Item 1" + expect(newDoc.roles).to.be.a("Array"); + expect(newDoc.roles.length).to.be.equal(1); + expect(newDoc.roles[0].name).to.be.equal( + "New Has Role 1" ); }); it("should successfully get child doc when the field is predefined in the input RenovationDocument", async function() { const newDoc = await renovation.model.newDoc({ - doctype: "Renovation Review" + doctype: "User" }); const predefinedChildDoc = await renovation.model.newDoc({ - doctype: "Renovation Review Item" + doctype: "Has Role" }); - newDoc.reviews = [predefinedChildDoc]; + newDoc.roles = [predefinedChildDoc]; const childDoc = await renovation.model.addChildDoc({ doc: newDoc, - field: "reviews" + field: "roles" }); - expect(childDoc.parent).to.be.equal("New Renovation Review 1"); - expect(childDoc.parenttype).to.be.equal("Renovation Review"); + expect(childDoc.parent).to.be.equal("New User 1"); + expect(childDoc.parenttype).to.be.equal("User"); expect(childDoc.idx).to.be.equal(2); - expect(newDoc.reviews).to.be.a("Array"); - expect(newDoc.reviews.length).to.be.equal(2); - expect(newDoc.reviews[0].name).to.be.equal( - "New Renovation Review Item 1" + expect(newDoc.roles).to.be.a("Array"); + expect(newDoc.roles.length).to.be.equal(2); + expect(newDoc.roles[0].name).to.be.equal( + "New Has Role 1" ); }); it("should successfully get child doc when the field is predefined in the input RenovationDocument [deprecated]", async function() { const newDoc = await renovation.model.newDoc({ - doctype: "Renovation Review" + doctype: "User" }); const predefinedChildDoc = await renovation.model.newDoc({ - doctype: "Renovation Review Item" + doctype: "Has Role" }); - newDoc.reviews = [predefinedChildDoc]; + newDoc.roles = [predefinedChildDoc]; - const childDoc = await renovation.model.addChildDoc(newDoc, "reviews"); + const childDoc = await renovation.model.addChildDoc(newDoc, "roles"); - expect(childDoc.parent).to.be.equal("New Renovation Review 1"); - expect(childDoc.parenttype).to.be.equal("Renovation Review"); + expect(childDoc.parent).to.be.equal("New User 1"); + expect(childDoc.parenttype).to.be.equal("User"); expect(childDoc.idx).to.be.equal(2); - expect(newDoc.reviews).to.be.a("Array"); - expect(newDoc.reviews.length).to.be.equal(2); - expect(newDoc.reviews[0].name).to.be.equal( - "New Renovation Review Item 1" + expect(newDoc.roles).to.be.a("Array"); + expect(newDoc.roles.length).to.be.equal(2); + expect(newDoc.roles[0].name).to.be.equal( + "New Has Role 1" ); }); it("should return a childDoc with DocField as input for field", async function() { const newDoc = await renovation.model.newDoc({ - doctype: "Renovation Review" + doctype: "User" }); const docMeta = await renovation.meta.getDocMeta({ - doctype: "Renovation Review" + doctype: "User" }); - const reviewsField = docMeta.data.fields.find( - field => field.fieldname === "reviews" + const rolesField = docMeta.data.fields.find( + field => field.fieldname === "roles" ); const childDoc = await renovation.model.addChildDoc({ doc: newDoc, - field: reviewsField + field: rolesField }); - expect(childDoc.parent).to.be.equal("New Renovation Review 1"); - expect(childDoc.parenttype).to.be.equal("Renovation Review"); + expect(childDoc.parent).to.be.equal("New User 1"); + expect(childDoc.parenttype).to.be.equal("User"); expect(childDoc.idx).to.be.equal(1); - expect(newDoc.reviews).to.be.a("Array"); - expect(newDoc.reviews.length).to.be.equal(1); - expect(newDoc.reviews[0].name).to.be.equal( - "New Renovation Review Item 1" + expect(newDoc.roles).to.be.a("Array"); + expect(newDoc.roles.length).to.be.equal(1); + expect(newDoc.roles[0].name).to.be.equal( + "New Has Role 1" ); }); }); @@ -301,7 +301,7 @@ describe("ModelController", function() { renovation.model.setLocalValue({ doctype: testDoctype, docname: "TEST SET LOCAL VALUE", - docfield: "reviewed_by", + docfield: "short_name", value: "test" }) ).to.throw(`Cache doc not found: ${testDoctype}:TEST SET LOCAL VALUE`); @@ -312,7 +312,7 @@ describe("ModelController", function() { renovation.model.setLocalValue({ doctype: testDoctype, docname: "TEST SET LOCAL VALUE", - docfield: "reviewed_by", + docfield: "short_name", value: "test" }) ).to.throw(`Cache doc not found: ${testDoctype}:TEST SET LOCAL VALUE`); @@ -322,12 +322,12 @@ describe("ModelController", function() { renovation.model.setLocalValue({ doctype: testDoctype, docname: `New ${testDoctype} 1`, - docfield: "reviewed_by", + docfield: "short_name", value: "test" }); expect( - renovation.model.locals[testDoctype][`New ${testDoctype} 1`].reviewed_by + renovation.model.locals[testDoctype][`New ${testDoctype} 1`].short_name ).to.be.equal("test"); }); it("should set the value for the local document [deprecated]", async function() { @@ -335,12 +335,12 @@ describe("ModelController", function() { renovation.model.setLocalValue( testDoctype, `New ${testDoctype} 1`, - "reviewed_by", + "short_name", "test" ); expect( - renovation.model.locals[testDoctype][`New ${testDoctype} 1`].reviewed_by + renovation.model.locals[testDoctype][`New ${testDoctype} 1`].short_name ).to.be.equal("test"); }); }); @@ -389,20 +389,20 @@ describe("ModelController", function() { it("should add child docs to cache", async function() { renovation.model.locals = {}; const newDoc = await renovation.model.newDoc({ - doctype: "Renovation Review" + doctype: "User" }); - const childDoc = await renovation.model.addChildDoc(newDoc, "reviews"); + const childDoc = await renovation.model.addChildDoc(newDoc, "roles"); renovation.model.addToLocals({ doc: newDoc }); expect( - renovation.model.locals["Renovation Review"]["New Renovation Review 1"] + renovation.model.locals["User"]["New User 1"] ).to.be.not.undefined; expect( - renovation.model.locals["Renovation Review Item"][ - "New Renovation Review Item 1" + renovation.model.locals["Has Role"][ + "New Has Role 1" ] ).to.be.not.undefined; }); From 974db7095b680fdf9da9d559eba1da6dc108265a Mon Sep 17 00:00:00 2001 From: Fahim Date: Mon, 17 Aug 2020 21:54:13 +0530 Subject: [PATCH 5/8] test: frappe.dashboard.controller.spec.ts --- ...ard.controller.spec.ts => frappe.dashboard.controller.spec.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/dashboard/{frappe.dashaboard.controller.spec.ts => frappe.dashboard.controller.spec.ts} (100%) diff --git a/src/dashboard/frappe.dashaboard.controller.spec.ts b/src/dashboard/frappe.dashboard.controller.spec.ts similarity index 100% rename from src/dashboard/frappe.dashaboard.controller.spec.ts rename to src/dashboard/frappe.dashboard.controller.spec.ts From 77a041a916aedf777d4782794c66055d5de66309 Mon Sep 17 00:00:00 2001 From: Fahim Date: Fri, 21 Aug 2020 23:00:13 +0530 Subject: [PATCH 6/8] tests: frappe.model.controller --- src/model/frappe.model.controller.spec.ts | 180 +++++++++++----------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/model/frappe.model.controller.spec.ts b/src/model/frappe.model.controller.spec.ts index f7f69e0..76b6d36 100644 --- a/src/model/frappe.model.controller.spec.ts +++ b/src/model/frappe.model.controller.spec.ts @@ -16,7 +16,7 @@ describe("Frappe Model Controller", function() { const validSecondUser = TestManager.secondaryUser; - const testDoctype = "Renovation User Agreement"; + const testDoctype = "TEST DOCTYPE"; before(async function() { renovation = await TestManager.init("frappe"); @@ -157,8 +157,9 @@ describe("Frappe Model Controller", function() { }); expect(docResponse.success).to.equals(true); expect(docResponse.data.length).greaterThan(0); - expect(docResponse.data.some(user => (user.roles as [{}]).length)).to.be - .true; + expect( + docResponse.data.some(user => (user.roles as [{}]).length > 0) + ).to.equals(true); }); it("should return all fields", async function() { @@ -173,7 +174,7 @@ describe("Frappe Model Controller", function() { }); describe("deleteDoc", async function() { - it("should delete a Renovation User Agreement successfully", async function() { + it(`should delete a ${testDoctype} successfully`, async function() { const doc = await renovation.model.newDoc({ doctype: testDoctype }); @@ -183,12 +184,12 @@ describe("Frappe Model Controller", function() { expect(savedDoc.success).equals(true); const deletedDoc = await renovation.model.deleteDoc({ doctype: testDoctype, - docname: "TESTING DELETION" + docname: savedDoc.data.name }); expect(deletedDoc.success).to.be.true; }); - it("should delete a Renovation User Agreement successfully [deprecated]", async function() { + it(`should delete a ${testDoctype} successfully [deprecated]`, async function() { const doc = await renovation.model.newDoc({ doctype: testDoctype }); doc.title = "TESTING DELETION"; @@ -196,7 +197,7 @@ describe("Frappe Model Controller", function() { expect(savedDoc.success).equals(true); const deletedDoc = await renovation.model.deleteDoc( testDoctype, - "TESTING DELETION" + savedDoc.data.name ); expect(deletedDoc.success).to.be.true; }); @@ -211,20 +212,20 @@ describe("Frappe Model Controller", function() { expect(savedDoc.success).equals(true); const docInCache = await renovation.model.getDoc({ doctype: testDoctype, - docname: "TESTING DELETION" + docname: savedDoc.data.name }); expect(docInCache.success).to.be.true; const deletedDoc = await renovation.model.deleteDoc({ doctype: testDoctype, - docname: "TESTING DELETION" + docname: savedDoc.data.name }); expect(deletedDoc.success).to.be.true; // try getDoc after deletion const docCache = await renovation.model.getDoc({ doctype: testDoctype, - docname: "TESTING DELETION" + docname: savedDoc.data.name }); expect(docCache.success).to.be.false; // verifies deleted from cache }); @@ -267,27 +268,25 @@ describe("Frappe Model Controller", function() { expect(resp.data[fieldName]).to.be.equal(fieldValue); }); - it("should return failure for non-existing doctype", async function() { + it("should return null for non-existing doctype", async function() { const resp = await renovation.model.getValue({ doctype: "NON-EXISTING", docname: "non_existing", docfield: fieldName }); - expect(resp.success).to.be.false; - expect(resp.httpCode).to.be.equal(404); - expect(resp.error.type).to.be.equal(RenovationError.NotFoundError); + expect(resp.success).to.be.true; + expect(resp.data).to.be.undefined; }); - it("should return undefined data for non-existing document", async function() { + it("should return null data for non-existing document", async function() { const resp = await renovation.model.getValue({ doctype: "User", docname: "non_existing", docfield: fieldName }); - expect(resp.success).to.be.false; - expect(resp.httpCode).to.be.equal(404); - expect(resp.error.type).to.be.equal(RenovationError.NotFoundError); + expect(resp.success).to.be.true; + expect(resp.data).to.be.undefined; }); it("should return failure for non-existing field", async function() { const resp = await renovation.model.getValue({ @@ -404,7 +403,7 @@ describe("Frappe Model Controller", function() { newDoc.title = "TESTING SAVE"; const savedDoc = await renovation.model.saveDoc({ doc: newDoc }); expect(savedDoc.success).to.be.true; - expect(renovation.model.locals[testDoctype]["TESTING SAVE"]).to.not.be + expect(renovation.model.locals[testDoctype][savedDoc.data.name]).to.not.be .undefined; }); it("should save document successfully and add to cache [deprecated]", async function() { @@ -412,7 +411,7 @@ describe("Frappe Model Controller", function() { newDoc.title = "TESTING SAVE 2"; const savedDoc = await renovation.model.saveDoc(newDoc); expect(savedDoc.success).to.be.true; - expect(renovation.model.locals[testDoctype]["TESTING SAVE 2"]).to.not.be + expect(renovation.model.locals[testDoctype][savedDoc.data.name]).to.not.be .undefined; }); @@ -529,7 +528,6 @@ describe("Frappe Model Controller", function() { doctype: testDoctype, docname: "EXISTING TESTING SUBMISSION" }); - }); }); @@ -540,7 +538,7 @@ describe("Frappe Model Controller", function() { await renovation.model.submitDoc({ doc: newDoc }); }); - it("should create and submit Renovation User Agreement", async function() { + it(`should create and submit ${testDoctype}`, async function() { const d = await renovation.model.newDoc({ doctype: testDoctype }); d.title = "TESTING SAVING AND SUBMISSION"; const r = await renovation.model.saveSubmitDoc({ doc: d }); @@ -554,7 +552,7 @@ describe("Frappe Model Controller", function() { expect(r.data.__unsaved).to.be.equal(0); }); - it("should create and submit Renovation User Agreement [deprecated]", async function() { + it(`should create and submit ${testDoctype} [deprecated]`, async function() { const d = await renovation.model.newDoc({ doctype: testDoctype }); d.title = "TESTING SAVING AND SUBMISSION 2"; const r = await renovation.model.saveSubmitDoc(d); @@ -883,7 +881,8 @@ describe("Frappe Model Controller", function() { }); expect(addTag.success).to.be.true; - expect(addTag.data).to.be.deep.equal({}); + // response.data can have _debug_messages + // expect(addTag.data).to.be.deep.equal({}); }); it("should remove a tag from a document User [deprecated]", async function() { @@ -894,7 +893,8 @@ describe("Frappe Model Controller", function() { ); expect(addTag.success).to.be.true; - expect(addTag.data).to.be.deep.equal({}); + // response.data can have _debug_messages + // expect(addTag.data).to.be.deep.equal({}); }); it("should fail for non-existing doctype", async function() { const addTag = await renovation.model.removeTag({ @@ -1005,22 +1005,15 @@ describe("Frappe Model Controller", function() { }); describe("getTags", function() { + const tags = ["FIRST TAG", "SECOND TAG", "THIRD TAG"]; before(async () => { - await renovation.model.addTag({ - doctype: "User", - docname: validSecondUser, - tag: "FIRST TAG" - }); - await renovation.model.addTag({ - doctype: "User", - docname: validSecondUser, - tag: "SECOND TAG" - }); - await renovation.model.addTag({ - doctype: "User", - docname: validSecondUser, - tag: "THIRD TAG" - }); + for (const t of tags) { + await renovation.model.addTag({ + doctype: "User", + docname: validSecondUser, + tag: t + }); + } }); it("should get 3 tags for the doctype User", async function() { @@ -1028,14 +1021,14 @@ describe("Frappe Model Controller", function() { expect(getTags.success).to.be.true; expect(getTags.data).to.an.instanceOf(Array); - expect(getTags.data.length).to.be.equal(3); + expect(tags.every(x => getTags.data.includes(x))).to.be.true; }); it("should get 3 tags for the doctype User [deprecated]", async function() { const getTags = await renovation.model.getTags("User"); expect(getTags.success).to.be.true; expect(getTags.data).to.an.instanceOf(Array); - expect(getTags.data.length).to.be.equal(3); + expect(tags.every(x => getTags.data.includes(x))).to.be.true; }); it("should return empty array for doctype without tags", async function() { const getTags = await renovation.model.getTags({ @@ -1045,7 +1038,8 @@ describe("Frappe Model Controller", function() { expect(getTags.success).to.be.true; expect(getTags.data).to.an.instanceOf(Array); - expect(getTags.data.length).to.be.equal(0); + // TODO: update this after frappe fixes get_tags + // expect(getTags.data.length).to.be.equal(0); }); it("should return 1 tag using LIKE SEC", async function() { @@ -1072,26 +1066,26 @@ describe("Frappe Model Controller", function() { }); after(async () => { - await renovation.model.removeTag({ - doctype: "User", - docname: validSecondUser, - tag: "FIRST TAG" - }); - await renovation.model.removeTag({ - doctype: "User", - docname: validSecondUser, - tag: "SECOND TAG" - }); - await renovation.model.removeTag({ - doctype: "User", - docname: validSecondUser, - tag: "THIRD TAG" - }); + for (const t of tags) { + await renovation.model.removeTag({ + doctype: "User", + docname: validSecondUser, + tag: t + }); + } }); }); }); describe("Assigning Docs to User", async function() { + const testDocName = "TEST-ASSIGN-DOC"; + before(async () => { + // make testDocType document + const testDoc = await renovation.model.newDoc({ doctype: testDoctype }); + testDoc.title = testDocName; + await renovation.model.saveDoc({ doc: testDoc }); + }); + const cleanUpFn = async () => { this.timeout(30000); @@ -1119,18 +1113,18 @@ describe("Frappe Model Controller", function() { await renovation.model.assignDoc({ assignTo: null, myself: true, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING ASSIGN DUPLICATE", priority: "High", dueDate: "2050-12-31" }) ); - it("should assign Renovation Review to Secondary User", async function() { + it(`should assign ${testDoctype} to Secondary User`, async function() { const r = await renovation.model.assignDoc({ assignTo: validSecondUser, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING ASSIGN", priority: "High", dueDate: "2050-12-31" @@ -1139,18 +1133,19 @@ describe("Frappe Model Controller", function() { expect(r.success).to.be.true; }); - it("should fail assigning same doc to a User since already assigned", async function() { - const r = await renovation.model.assignDoc({ - assignTo: null, - myself: true, - doctype: "Renovation Review", - docname: "RE-00001", - description: "TESTING ASSIGN DUPLICATE", - priority: "High", - dueDate: "2050-12-31" - }); - expect(r.success).to.be.false; - }); + // v13 - doesnt throw error now. It just prints message that the user is assigned already + // it("should fail assigning same doc to a User since already assigned", async function() { + // const r = await renovation.model.assignDoc({ + // assignTo: null, + // myself: true, + // doctype: testDoctype, + // docname: testDocName, + // description: "TESTING ASSIGN DUPLICATE", + // priority: "High", + // dueDate: "2050-12-31" + // }); + // expect(r.success).to.be.false; + // }); after(async () => await cleanUpFn()); }); @@ -1248,25 +1243,25 @@ describe("Frappe Model Controller", function() { await renovation.model.assignDoc({ assignTo: null, myself: true, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING GET ASSIGNED", priority: "High", dueDate: "2050-12-31" }); await renovation.model.assignDoc({ assignTo: validSecondUser, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING GET ASSIGNED", priority: "High", dueDate: "2050-12-31" }); }); - it("should have Primary & Secondary User in the list of Users assigned to Renovation Review RE-00001", async function() { + it(`should have Primary & Secondary User in the list of Users assigned to ${testDoctype} ${testDocName}`, async function() { const r = await renovation.model.getUsersAssignedToDoc({ - doctype: "Renovation Review", - docname: "RE-00001" + doctype: testDoctype, + docname: testDocName }); expect(r.success).to.be.true; @@ -1286,30 +1281,30 @@ describe("Frappe Model Controller", function() { await renovation.model.assignDoc({ assignTo: null, myself: true, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING COMPLETED", priority: "High", dueDate: "2050-12-31" }); await renovation.model.assignDoc({ assignTo: validSecondUser, - doctype: "Renovation Review", - docname: "RE-00001", + doctype: testDoctype, + docname: testDocName, description: "TESTING COMPLETED", priority: "High", dueDate: "2050-12-31" }); }); this.timeout(20000); - it("Complete Renovation Review Assignments", async function() { + it(`Complete ${testDoctype} Assignments`, async function() { const promises = []; for (const user of [validUser, validSecondUser]) { promises.push( renovation.model.completeDocAssignment({ assignedTo: user, - doctype: "Renovation Review", - docname: "RE-00001" + doctype: testDoctype, + docname: testDocName }) ); } @@ -1320,6 +1315,13 @@ describe("Frappe Model Controller", function() { }); after(async () => await cleanUpFn()); }); + + after(async () => { + await renovation.model.deleteDoc({ + doctype: testDoctype, + docname: testDocName + }); + }); }); describe("Export Report", function() { From 564280f75de80e740b4b00ff07a18a1b32974161 Mon Sep 17 00:00:00 2001 From: Fahim Date: Sat, 22 Aug 2020 16:19:02 +0530 Subject: [PATCH 7/8] tests: frappe.perm.controller --- src/perm/frappe.perm.controller.spec.ts | 60 ++++++++++--------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/src/perm/frappe.perm.controller.spec.ts b/src/perm/frappe.perm.controller.spec.ts index 26ffe14..7db23d7 100644 --- a/src/perm/frappe.perm.controller.spec.ts +++ b/src/perm/frappe.perm.controller.spec.ts @@ -230,22 +230,20 @@ describe("FrappePermController", function() { describe("canCancel", function() { it("should return true for a System Manager user", async function() { const canCancel = await renovation.perm.canCancel({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canCancel).to.be.true; }); it("should return true for a System Manager user [deprecated]", async function() { - const canCancel = await renovation.perm.canCancel( - "Renovation User Agreement" - ); + const canCancel = await renovation.perm.canCancel("TEST DOCTYPE"); expect(canCancel).to.be.true; }); it("should return false for a non System Manager user", async function() { await loginSecondary(); const canCancel = await renovation.perm.canCancel({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canCancel).to.be.false; @@ -293,22 +291,20 @@ describe("FrappePermController", function() { describe("canExport", function() { it("should return true for a System Manager user", async function() { const canExport = await renovation.perm.canExport({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canExport).to.be.true; }); it("should return true for a System Manager user [deprecated]", async function() { - const canExport = await renovation.perm.canExport( - "Renovation User Agreement" - ); + const canExport = await renovation.perm.canExport("TEST DOCTYPE"); expect(canExport).to.be.true; }); it("should return false for a non System Manager user", async function() { await loginSecondary(); const canExport = await renovation.perm.canExport({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canExport).to.be.false; @@ -318,22 +314,20 @@ describe("FrappePermController", function() { describe("canPrint", function() { it("should return true for a System Manager user", async function() { const canPrint = await renovation.perm.canPrint({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canPrint).to.be.true; }); it("should return true for a System Manager user [deprecated]", async function() { - const canPrint = await renovation.perm.canPrint( - "Renovation User Agreement" - ); + const canPrint = await renovation.perm.canPrint("TEST DOCTYPE"); expect(canPrint).to.be.true; }); it("should return false for a non System Manager user", async function() { await loginSecondary(); const canPrint = await renovation.perm.canPrint({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canPrint).to.be.false; @@ -362,20 +356,20 @@ describe("FrappePermController", function() { describe("canSearch", function() { it("should return true for a System Manager user", async function() { const canSearch = await renovation.perm.canSearch({ - doctype: "Bank" + doctype: "TEST DOCTYPE" }); expect(canSearch).to.be.true; }); it("should return true for a System Manager user [deprecated]", async function() { - const canSearch = await renovation.perm.canSearch("Bank"); + const canSearch = await renovation.perm.canSearch("TEST DOCTYPE"); expect(canSearch).to.be.true; }); it("should return false for a non System Manager user", async function() { await loginSecondary(); const canSearch = await renovation.perm.canSearch({ - doctype: "Bank" + doctype: "TEST DOCTYPE" }); expect(canSearch).to.be.false; @@ -385,22 +379,20 @@ describe("FrappePermController", function() { describe("canGetReport", function() { it("should return true for a System Manager user", async function() { const canGetReport = await renovation.perm.canGetReport({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canGetReport).to.be.true; }); it("should return true for a System Manager user [deprecated]", async function() { - const canGetReport = await renovation.perm.canGetReport( - "Renovation User Agreement" - ); + const canGetReport = await renovation.perm.canGetReport("TEST DOCTYPE"); expect(canGetReport).to.be.true; }); it("should return false for a non System Manager user", async function() { await loginSecondary(); const canGetReport = await renovation.perm.canGetReport({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canGetReport).to.be.false; @@ -427,22 +419,20 @@ describe("FrappePermController", function() { describe("canSubmit", function() { it("should return false for a System Manager user", async function() { const canSubmit = await renovation.perm.canSubmit({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canSubmit).to.be.false; }); it("should return false for a System Manager user [deprecated]", async function() { - const canSubmit = await renovation.perm.canSubmit( - "Renovation User Agreement" - ); + const canSubmit = await renovation.perm.canSubmit("TEST DOCTYPE"); expect(canSubmit).to.be.false; }); it("should return false for logged out user", async function() { await renovation.auth.logout(); const canSubmit = await renovation.perm.canSubmit({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canSubmit).to.be.false; @@ -452,23 +442,21 @@ describe("FrappePermController", function() { describe("canAmend", function() { it("should return false for a System Manager user", async function() { const canAmend = await renovation.perm.canAmend({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canAmend).to.be.false; }); it("should return false for a System Manager user [deprecated]", async function() { - const canAmend = await renovation.perm.canAmend( - "Renovation User Agreement" - ); + const canAmend = await renovation.perm.canAmend("TEST DOCTYPE"); expect(canAmend).to.be.false; }); it("should return false for logged out user", async function() { await renovation.auth.logout(); const canAmend = await renovation.perm.canAmend({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canAmend).to.be.false; @@ -478,7 +466,7 @@ describe("FrappePermController", function() { describe("canRecursiveDelete", function() { it("should return false for a System Manager user", async function() { const canRecursiveDelete = await renovation.perm.canRecursiveDelete({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canRecursiveDelete).to.be.false; @@ -486,7 +474,7 @@ describe("FrappePermController", function() { it("should return false for a System Manager user [deprecated]", async function() { const canRecursiveDelete = await renovation.perm.canRecursiveDelete( - "Renovation User Agreement" + "TEST DOCTYPE" ); expect(canRecursiveDelete).to.be.false; @@ -494,7 +482,7 @@ describe("FrappePermController", function() { it("should return false for logged out user", async function() { await renovation.auth.logout(); const canRecursiveDelete = await renovation.perm.canRecursiveDelete({ - doctype: "Renovation User Agreement" + doctype: "TEST DOCTYPE" }); expect(canRecursiveDelete).to.be.false; From b323e9dc0fb44ca02151df4aa7d9c5c950c3bb82 Mon Sep 17 00:00:00 2001 From: Fahim Date: Sat, 22 Aug 2020 17:07:53 +0530 Subject: [PATCH 8/8] tests: file.utils.spec.ts --- src/storage/file.utils.spec.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/storage/file.utils.spec.ts b/src/storage/file.utils.spec.ts index 348ea16..f2a382f 100644 --- a/src/storage/file.utils.spec.ts +++ b/src/storage/file.utils.spec.ts @@ -34,7 +34,8 @@ describe("File Utils", function() { path.join(__dirname, "..", "tests", "sample.txt") ); expect(fileResult.fileName).to.be.equal("sample.txt"); - expect(fileResult.fileSize).to.be.equal(27); + expect(fileResult.fileSize).to.be.gte(24); + expect(fileResult.fileSize).to.be.lte(28); }); describe("getBase64FromBuffer", function() { @@ -59,7 +60,8 @@ describe("File Utils", function() { const fileResult = await getBase64FromBuffer(buffer, "sample.txt"); expect(fileResult.fileName).to.be.equal("sample.txt"); - expect(fileResult.fileSize).to.be.equal(27); + expect(fileResult.fileSize).to.be.gte(24); + expect(fileResult.fileSize).to.be.lte(28); }); }); @@ -87,7 +89,8 @@ describe("File Utils", function() { ); expect(fileResult.fileName).to.be.equal("sample.txt"); - expect(fileResult.fileSize).to.be.equal(25); + expect(fileResult.fileSize).to.be.gte(24); + expect(fileResult.fileSize).to.be.lte(28); }); }); });