145 lines
4.1 KiB
JavaScript
145 lines
4.1 KiB
JavaScript
|
// const fixture = require('../fixtures/example.json');
|
||
|
|
||
|
// describe("CRUD Operations", () => {
|
||
|
// it("GET API testing using cypress", () => {
|
||
|
// cy.request("GET", "http://localhost:3000/api/comment").should(
|
||
|
// (response) => {
|
||
|
// expect(response.status).to.eq(200);
|
||
|
// }
|
||
|
// );
|
||
|
// });
|
||
|
|
||
|
// it("POST API testing using cypress", () => {
|
||
|
// cy.request("POST", "http://localhost:3000/api/comment", {
|
||
|
// comment: "Good Morning Pineapple",
|
||
|
// blogId: "63f2b5a91c9e440234abce14",
|
||
|
// }).should((response) => {
|
||
|
// expect(response.status).to.eq(201);
|
||
|
// });
|
||
|
// });
|
||
|
// it("PUT API testing using cypress", () => {
|
||
|
// cy.request(
|
||
|
// "PUT",
|
||
|
// "http://localhost:3000/api/comment/679b1b0af60b0c5db3245f01",
|
||
|
// {
|
||
|
// comment: "Good Morning Pineapple",
|
||
|
// blogId: "63f2b5a91c9e440234abce15",
|
||
|
// }
|
||
|
// ).should((response) => {
|
||
|
// expect(response.status).to.eq(200);
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
// // it("DELETE API testing usin cypress", () => {
|
||
|
// // cy.request(
|
||
|
// // "DELETE",
|
||
|
// // "http://localhost:3000/api/comment/679b5133720786787a6c238a"
|
||
|
// // ).should((response) => {
|
||
|
// // expect(response.status).to.eq(204);
|
||
|
// // });
|
||
|
// // });
|
||
|
// });
|
||
|
|
||
|
// describe("Frontend API Mocking", () => {
|
||
|
// beforeEach(() => {
|
||
|
// cy.visit("http://localhost:3000");
|
||
|
// cy.intercept("GET", "http://localhost:3000/api/tagss", {
|
||
|
// fixture: "example.json",
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
// it("should mock the API response and display the albums", () => {
|
||
|
// cy.request("http://localhost:3000//api/tags");
|
||
|
// cy.get('a[href="/api/tags"]').click();
|
||
|
// cy.get("body").should("contain", "bk-1");
|
||
|
// cy.get("body").should("contain", "bk-2");
|
||
|
// cy.get("body").should("contain", "bk-3");
|
||
|
// cy.get("body").should("contain", "bk-4");
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
// describe("CRUD Operations", () => {
|
||
|
// it("GET API testing using cypress", () => {
|
||
|
// cy.request("GET", "http://localhost:3000//api/tags").should((response) => {
|
||
|
// expect(response.status).to.eq(200);
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
// it("POST API testing using cypress", () => {
|
||
|
// cy.request("POST", "http://localhost:3000//api/tags", {
|
||
|
// name: "Ki haal chaal hai dosto hello.",
|
||
|
// blogIDs: [
|
||
|
// "63f1b5a91c9d441234abcd12",
|
||
|
// "63f1b5a91c9d441234abcd34",
|
||
|
// "63f1b5a91c9d441234abcd56",
|
||
|
// ],
|
||
|
// }).should((response) => {
|
||
|
// expect(response.status).to.eq(201);
|
||
|
// });
|
||
|
// });
|
||
|
// it("PUT API testing using cypress", () => {
|
||
|
// cy.request(
|
||
|
// "PUT",
|
||
|
// "http://localhost:3000/api/tags/6791d0adf0cb06cbc9677cb8",
|
||
|
// {
|
||
|
// comment: "Good Morning Pineapple",
|
||
|
// blogId: "63f2b5a91c9e440234abce15",
|
||
|
// }
|
||
|
// ).should((response) => {
|
||
|
// expect(response.status).to.eq(200);
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
// it("DELETE API testing usin cypress", () => {
|
||
|
// cy.request(
|
||
|
// "DELETE",
|
||
|
// "http://localhost:3000//api/tags/6791e5ebc1c4440968effd45"
|
||
|
// ).should((response) => {
|
||
|
// expect(response.status).to.eq(200);
|
||
|
// });
|
||
|
// });
|
||
|
// });
|
||
|
|
||
|
|
||
|
|
||
|
describe("API Mocking", () => {
|
||
|
beforeEach(() => {
|
||
|
cy.intercept("POST", "http://localhost:3000/api/tags", {
|
||
|
statusCode: 201,
|
||
|
body: {
|
||
|
name: "FakeName",
|
||
|
blogIDs: ["fakeBlogID1", "fakeBlogID2"]
|
||
|
},
|
||
|
{console.log(body);},
|
||
|
}).as("createBlog");
|
||
|
});
|
||
|
|
||
|
it("Create blogs with fake data", () => {
|
||
|
cy.request({
|
||
|
method: "GET",
|
||
|
url: "http://localhost:3000/api/tags",
|
||
|
|
||
|
}).then((res) => {
|
||
|
expect(res.status).to.eq(200);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("Create blogs with fake data", () => {
|
||
|
cy.request({
|
||
|
method: "POST",
|
||
|
url: "http://localhost:3000/api/tags",
|
||
|
body: {
|
||
|
name: "Faketags",
|
||
|
blogIDs: ["3248729354523", "32842987352823"]
|
||
|
},
|
||
|
failOnStatusCode: false,
|
||
|
}).then((res) => {
|
||
|
expect(res.status).to.eq(500);
|
||
|
console.log(res.body.name,";;;;;;;;;;;;;;;;;;;;;;;");
|
||
|
console.log(res.name,";:::::::::::::::::::::::::::");
|
||
|
expect(res.name).to.eq("Faketags");
|
||
|
expect(res.blogIDs).to.deep.eq(["3248729354523", "32842987352823"]);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
|