Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(examples): add e2e test to supabase and strapi-v4 examples #4413

Merged
merged 4 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cypress/fixtures/strapi-v4-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"email": "demo@refine.dev",
"password": "demodemo"
}
4 changes: 4 additions & 0 deletions cypress/fixtures/supabase-credentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"email": "info@refine.dev",
"password": "refine-supabase"
}
121 changes: 121 additions & 0 deletions cypress/support/commands/intercepts/api-fake-rest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/// <reference types="cypress" />
/// <reference types="../../index.d.ts" />

import { getIdFromURL } from "../../../utils";

const hostname = "api.fake-rest.refine.dev";

Cypress.Commands.add("interceptGETPosts", () => {
return cy
.intercept(
{
method: "GET",
hostname: hostname,
pathname: "/posts",
},
{
fixture: "posts.json",
},
)
.as("getPosts");
});

Cypress.Commands.add("interceptGETPost", () => {
return cy
.fixture("posts")
.then((posts) => {
return cy.intercept(
{
method: "GET",
hostname: hostname,
pathname: "/posts/*",
},

(req) => {
const id = getIdFromURL(req.url);
const post = posts.find((post) => post.id === id);

if (!post) {
req.reply(404, {});
return;
}

req.reply(post);
},
);
})
.as("getPost");
});

Cypress.Commands.add("interceptPOSTPost", () => {
return cy.fixture("posts").then((posts) =>
cy
.intercept(
{
method: "POST",
hostname: hostname,
pathname: "/posts",
},
(req) => {
const merged = Object.assign({}, req.body, {
id: posts.length + 1,
});

return req.reply(merged);
},
)
.as("postPost"),
);
});

Cypress.Commands.add("interceptPATCHPost", () => {
return cy
.fixture("posts")
.then((posts) => {
return cy.intercept(
{
method: "PATCH",
hostname: hostname,
pathname: "/posts/*",
},

(req) => {
const id = getIdFromURL(req.url);
const post = posts.find((post) => post.id === id);

if (!post) {
return req.reply(404, {});
}
const merged = Object.assign({}, post, req.body);
return req.reply(merged);
},
);
})
.as("patchPost");
});

Cypress.Commands.add("interceptDELETEPost", () => {
return cy
.intercept(
{
method: "DELETE",
hostname: hostname,
pathname: "/posts/*",
},
{},
)
.as("deletePost");
});

Cypress.Commands.add("interceptGETCategories", () => {
return cy
.intercept(
{
method: "GET",
hostname: hostname,
pathname: "/categories",
},
{ fixture: "categories.json" },
)
.as("getCategories");
});
123 changes: 4 additions & 119 deletions cypress/support/commands/intercepts/index.ts
Original file line number Diff line number Diff line change
@@ -1,119 +1,4 @@
/// <reference types="cypress" />
/// <reference types="../../index.d.ts" />

import { getIdFromURL } from "../../../utils";

Cypress.Commands.add("interceptGETPosts", () => {
return cy
.intercept(
{
method: "GET",
hostname: "api.fake-rest.refine.dev",
pathname: "/posts",
},
{
fixture: "posts.json",
},
)
.as("getPosts");
});

Cypress.Commands.add("interceptGETPost", () => {
return cy
.fixture("posts")
.then((posts) => {
return cy.intercept(
{
method: "GET",
hostname: "api.fake-rest.refine.dev",
pathname: "/posts/*",
},

(req) => {
const id = getIdFromURL(req.url);
const post = posts.find((post) => post.id === id);

if (!post) {
req.reply(404, {});
return;
}

req.reply(post);
},
);
})
.as("getPost");
});

Cypress.Commands.add("interceptPOSTPost", () => {
return cy.fixture("posts").then((posts) =>
cy
.intercept(
{
method: "POST",
hostname: "api.fake-rest.refine.dev",
pathname: "/posts",
},
(req) => {
const merged = Object.assign({}, req.body, {
id: posts.length + 1,
});

return req.reply(merged);
},
)
.as("postPost"),
);
});

Cypress.Commands.add("interceptPATCHPost", () => {
return cy
.fixture("posts")
.then((posts) => {
return cy.intercept(
{
method: "PATCH",
hostname: "api.fake-rest.refine.dev",
pathname: "/posts/*",
},

(req) => {
const id = getIdFromURL(req.url);
const post = posts.find((post) => post.id === id);

if (!post) {
return req.reply(404, {});
}
const merged = Object.assign({}, post, req.body);
return req.reply(merged);
},
);
})
.as("patchPost");
});

Cypress.Commands.add("interceptDELETEPost", () => {
return cy
.intercept(
{
method: "DELETE",
hostname: "api.fake-rest.refine.dev",
pathname: "/posts/*",
},
{},
)
.as("deletePost");
});

Cypress.Commands.add("interceptGETCategories", () => {
return cy
.intercept(
{
method: "GET",
hostname: "api.fake-rest.refine.dev",
pathname: "/categories",
},
{ fixture: "categories.json" },
)
.as("getCategories");
});
// add commands to the Cypress chain
import "./api-fake-rest";
import "./supabase";
import "./strapi-v4";
Loading
Loading