From 97e8179164d7eeea9b7ab8f69b5211fbc7d1b898 Mon Sep 17 00:00:00 2001 From: Andrzej Stepien Date: Sat, 9 Sep 2023 16:44:54 +0200 Subject: [PATCH] test delete endpoints --- objects/Entity.mjs | 2 +- test.db | Bin 40960 -> 40960 bytes test/endpoints.test.mjs | 80 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/objects/Entity.mjs b/objects/Entity.mjs index 9233c07..8ec5ed5 100644 --- a/objects/Entity.mjs +++ b/objects/Entity.mjs @@ -25,7 +25,7 @@ export default class Entity{ if(!this?.id){throw new Error("cannot delete without an id!")} return db(this.table) .where('id',this.id) - this.del() + .del() } } diff --git a/test.db b/test.db index 1cdd85cb5df67856005b9d7cfbbecb14302ec0b8..245ded8d263311bc3b8ef687864aaca3f9d67c77 100644 GIT binary patch delta 97 zcmZoTz|?SnX@V3J(}amKPC#;F!b^U}4;vfjvP(#d>nfL|7MGMWFfj0oi-OrXnR(fp t|BK5>FthXh-mIu_k55pNQ9K_k2UNz(B+mF{Gr#>uDJBMn%}i1MTmk8_9kc)d delta 82 zcmZoTz|?SnX@V3Jqwqu-Cm^{o;Uz!glZ}mY*(IdKb(Kp}i%ZJO%k?tzN>YpRQcLub m^K&=<7nhS@uDJK4xo0+2ixdH%Z;2XC9 diff --git a/test/endpoints.test.mjs b/test/endpoints.test.mjs index 9c576e9..87de5b8 100644 --- a/test/endpoints.test.mjs +++ b/test/endpoints.test.mjs @@ -18,7 +18,7 @@ app.use('/api',getEndpoints(data)) app.use('/api', endpoints(db)) - +describe("testing endpoints...",async function(){ describe("Testing GET endpoints", async function(){ describe("GET stories",async function(){ it("should return a status code of 200 and an array", async function(){ @@ -302,4 +302,82 @@ describe("testing /edit endpoints",async function(){ }) }) +}) +describe("testing /delete endpoints",async function(){ + describe("/story/delete",async function(){ + it("item should be deleted from db",async function(){ + let id = await db('stories'). + insert({ + title:"#test", + word_count:500 + }) + .returning('id') + id=id[0].id + + await chai.request(app) + .post('/api/story/delete') + .send({id}) + + const res = await db('stories') + .select('*') + .where('id',id) + expect(res).to.have.lengthOf(0) + }) + + await db('stories') + .where('title','#test') + .del() + }) + describe("/publication/delete",async function(){ + it("item should be deleted from db",async function(){ + let id = await db('pubs'). + insert({ + title:"#test", + link:'link' + }) + .returning('id') + id=id[0].id + + await chai.request(app) + .post('/api/publication/delete') + .send({id}) + + const res = await db('pubs') + .select('*') + .where('id',id) + expect(res).to.have.lengthOf(0) + }) + + await db('pubs') + .where('title','#test') + .del() + }) + describe("/submission/delete",async function(){ + it("item should be deleted from db",async function(){ + let id = await db('subs'). + insert({ + story_id:1, + pub_id:1, + response_id:1, + date_submitted:"1066-01-01", + date_responded:"1066-01-01" + }) + .returning('id') + id=id[0].id + + await chai.request(app) + .post('/api/submission/delete') + .send({id}) + + const res = await db('subs') + .select('*') + .where('id',id) + expect(res).to.have.lengthOf(0) + }) + + await db('subs') + .where('date_submitted','1066-01-01') + .del() + }) +}) }) \ No newline at end of file