Skip to content

Commit

Permalink
Tests/meta data (#230)
Browse files Browse the repository at this point in the history
* test(bookmarks): ✅ added test and new api for get bookmark by id

* test(meta data): 🚧 WIP

* test(meta data): ✅ added all the meta data test cases

* test(meta data): 🐛 fixed TS issues
  • Loading branch information
abhishekmg authored Aug 26, 2024
1 parent e40213c commit ca01388
Show file tree
Hide file tree
Showing 13 changed files with 9,727 additions and 1,927 deletions.
6 changes: 6 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { defineConfig } from "cypress";
import dotenv from "dotenv";

// Load environment variables from .env file
dotenv.config();

export default defineConfig({
e2e: {
baseUrl: process.env.NEXT_PUBLIC_VERCEL_URL,

// on, config
setupNodeEvents() {
// implement node event listeners here
Expand Down
60 changes: 60 additions & 0 deletions cypress/e2e/api-tests/meta-data/bookmark.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//@ts-nocheck

describe("Meta data testing", () => {
beforeEach(() => {
// cy.visit("/all-bookmarks");
cy.visit("/login");
});

it("bookmark meta_data check", async () => {
cy.login(
Cypress.env("test_email") as string,
Cypress.env("test_password") as string,
);

cy.request(`/api/bookmark/add-bookmark-min-data`, {
category_id: 0,
update_access: true,
url: "https://unsplash.com/photos/a-city-street-with-a-lot-of-tall-buildings-badrIRxBqmk",
}).as("addRequest");

let bookmarkId;

cy.get("@addRequest")?.then((addBookmarkData) => {
bookmarkId = addBookmarkData?.body?.data?.[0]?.id;

// check meta data

cy.reload();

cy.wait(40000);

cy.request(`/api/v1/bookmarks/get/fetch-by-id`, {
data: {
id: addBookmarkData?.body?.data?.[0]?.id,
},
}).as("fetchRequest");

cy.get("@fetchRequest").then((data) => {
expect(data?.body?.data?.[0]?.meta_data).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ocr).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.img_caption).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ogImgBlurUrl).to.not.be.null;
});

// delete the bookmark
cy.request(`/api/bookmark/delete-bookmark`, {
data: {
deleteData: [
{
id: addBookmarkData?.body?.data?.[0]?.id,
ogImage: addBookmarkData?.body?.data?.[0]?.ogImage,
title: addBookmarkData?.body?.data?.[0]?.title,
url: addBookmarkData?.body?.data?.[0]?.url,
},
],
},
});
});
});
});
75 changes: 75 additions & 0 deletions cypress/e2e/api-tests/meta-data/files.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//@ts-nocheck

describe("Meta data testing", () => {
beforeEach(() => {
// cy.visit("/all-bookmarks");
cy.visit("/login");
});

it("file upload check", async () => {
cy.wait(3000);

cy.login(
Cypress.env("test_email") as string,
Cypress.env("test_password") as string,
);

const headers = {
Accept: "application/json",
"Content-Type": "application/json",
};
cy.request({
method: "POST",
url: "/api/v1/tests/file/post/upload", // Ensure this URL is correct
body: {
name: "image.png",
type: "image/png",
uploadFileNamePath: "m05eqwhx-image.png",
},
headers: headers,
}).as("uploadRequest");

cy.get("@uploadRequest")?.then((addBookmarkData) => {
bookmarkId = addBookmarkData?.body?.data?.[0]?.id;

// check meta data

cy.reload();

cy.wait(60000);

cy.reload();

cy.wait(2000);

cy.request(`/api/v1/bookmarks/get/fetch-by-id`, {
data: {
id: addBookmarkData?.body?.data?.[0]?.id,
},
}).as("fetchRequest");

cy.get("@fetchRequest").then((data) => {
cy.wait(1000);

expect(data?.body?.data?.[0]?.meta_data).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ocr).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.img_caption).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ogImgBlurUrl).to.not.be.null;
});

// delete the bookmark

cy.request("DELETE", `/api/v1/bookmarks/delete/non-cascade`, {
data: {
id: addBookmarkData?.body?.data?.[0]?.id,
},
}).as("deleteRequest");

cy.get("@deleteRequest").then((data) => {
cy.wait(1000);

expect(data.status).to.eq(200);
});
});
});
});
76 changes: 76 additions & 0 deletions cypress/e2e/api-tests/meta-data/tweet.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//@ts-nocheck

describe("Meta data testing", () => {
beforeEach(() => {
// cy.visit("/all-bookmarks");
cy.visit("/login");
});

it("tweet upload check", async () => {
cy.wait(3000);

cy.login(
Cypress.env("test_email") as string,
Cypress.env("test_password") as string,
);

// add the tweet
cy.request("POST", `/api/v1/twitter/sync`, {
data: [
{
description: "test tweet description",
ogImage: "https://pbs.twimg.com/media/GVRv2bGWcAA--aC.jpg",
title: "test title",
type: "tweet",
url: `https://x.com/passportprofit/status/${Math.floor(
Math.random() * 1000000000,
)}`, // we are generating random number , as the duplicates are removed in the sync api
meta_data: {
twitter_avatar_url: "test url",
},
inserted_at: "2024-08-22T14:30:00Z",
sort_index: "89",
},
],
}).as("addRequest");

let bookmarkId;

cy.get("@addRequest")?.then((addBookmarkData) => {
bookmarkId = addBookmarkData?.body?.data?.[0]?.id;

// check meta data

cy.reload();

cy.wait(40000);

cy.request(`/api/v1/bookmarks/get/fetch-by-id`, {
data: {
id: addBookmarkData?.body?.data?.[0]?.id,
},
}).as("fetchRequest");

cy.get("@fetchRequest").then((data) => {
expect(data?.body?.data?.[0]?.meta_data).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ocr).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.img_caption).to.not.be.null;
expect(data?.body?.data?.[0]?.meta_data?.ogImgBlurUrl).to.not.be.null;
});

// delete the bookmark
cy.request(`/api/bookmark/delete-bookmark`, {
data: {
deleteData: [
{
id: addBookmarkData?.body?.data?.[0]?.id,
ogImage: addBookmarkData?.body?.data?.[0]?.ogImage,
title: addBookmarkData?.body?.data?.[0]?.title,
url: addBookmarkData?.body?.data?.[0]?.url,
},
],
},
});
});
});
});
Loading

0 comments on commit ca01388

Please sign in to comment.