mufidu / booku

0 stars 1 forks source link

Sweep: Refactor app.test.js to implement token #109

Closed mufidu closed 5 months ago

mufidu commented 5 months ago

Details

Refactor app.test.js so it uses token, by logging in via /auth/login, using mufid.to@gmail.com as email and password as password. Format it like other tests in the test folder (for example, make it similar to user.test.js)

Checklist - [X] Modify `test/app.test.js` ✓ https://github.com/mufidu/booku/commit/a78dfd2cbc37b80f59f4eeaf8eefcb326707114b [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_apptestjs_to_implement_token/test/app.test.js) - [X] Running GitHub Actions for `test/app.test.js` ✓ [Edit](https://github.com/mufidu/booku/edit/sweep/refactor_apptestjs_to_implement_token/test/app.test.js)
sweep-ai[bot] commented 5 months ago

🚀 Here's the PR! #110

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: bbdb1959f6)

[!TIP] I can email you next time I complete a pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/mufidu/booku/blob/f762e74c005fb9a64008bb9085531ddece30dfe0/test/app.test.js#L1-L84 https://github.com/mufidu/booku/blob/f762e74c005fb9a64008bb9085531ddece30dfe0/test/user.test.js#L1-L44

Step 2: ⌨️ Coding

--- 
+++ 
@@ -5,6 +5,20 @@

 chai.use(chaiHttp);
 const { expect } = chai;
+
+let token;
+
+before(async () => {
+  try {
+    const res = await chai.request(app)
+      .post("/auth/login")
+      .send({email: "mufid.to@gmail.com", password: "password"});
+    token = res.body.jwt;
+  } catch (error) {
+    console.error("Login failed", error);
+    throw error;
+  }
+});

 describe("Book API", () => {
     // Test for GET route "/books"
@@ -23,7 +37,7 @@
             category: "Science",
             cover: "Test Cover",
         };
-        const res = await chai.request(app).post("/books").send(book);
+        const res = await chai.request(app).post("/books").send(book).set("Authorization", `Bearer ${token}`);
         expect(res).to.have.status(200);
         expect(res.body).to.be.a("object");
         expect(res.body).to.have.property("title").eql(book.title);
@@ -62,7 +76,8 @@
         const res = await chai
             .request(app)
             .put(`/books/${book.id}`)
-            .send({ title: "Updated Test Book" });
+            .send({ title: "Updated Test Book" })
+            .set("Authorization", `Bearer ${token}`);
         expect(res).to.have.status(200);
         expect(res.body).to.be.a("object");
         expect(res.body).to.have.property("title").eql("Updated Test Book");
@@ -78,7 +93,7 @@
             cover: "Test Cover",
         });
         await book.save();
-        const res = await chai.request(app).delete(`/books/${book.id}`);
+        const res = await chai.request(app).delete(`/books/${book.id}`).set("Authorization", `Bearer ${token}`);
         expect(res).to.have.status(200);
         expect(res.body).to.equal(`${book.title} deleted`);
     });

Ran GitHub Actions for a78dfd2cbc37b80f59f4eeaf8eefcb326707114b:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/refactor_apptestjs_to_implement_token.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.