Skip to content

Commit

Permalink
test(examples): add e2e test to supabase and strapi-v4 examples (#4413)
Browse files Browse the repository at this point in the history
* test(examples): add e2e test to supabase and strapi-v4 examples

* chore(examples): remove show button

* chore(examples): remove show component

* test(examples): add show component and test to data-provider-strapi-v4
  • Loading branch information
alicanerdurmaz committed May 30, 2023
1 parent 5cec6de commit 57968c0
Show file tree
Hide file tree
Showing 23 changed files with 1,273 additions and 155 deletions.
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

0 comments on commit 57968c0

Please sign in to comment.