Skip to content

Commit

Permalink
test(supabase): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir committed Apr 25, 2024
1 parent b1515a6 commit 9675681
Show file tree
Hide file tree
Showing 20 changed files with 2,529 additions and 1,194 deletions.
227 changes: 188 additions & 39 deletions packages/supabase/test/create/index.mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
import nock from "nock";

nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
encodedQueryParams: true,
})
.post("/auth/v1/token", {
email: "info@refine.dev",
password: "refine-supabase",
gotrue_meta_security: {},
})
.query({ grant_type: "password" })
.reply(
200,
{
access_token:
"eyJhbGciOiJIUzI1NiIsImtpZCI6IldGWnFuOWt6bnBJZTIvL2wiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzE0MDM5MDk1LCJpYXQiOjE3MTQwMzU0OTUsImlzcyI6Imh0dHBzOi8vaXdkZnp2ZnFidG9rcWV0bWJtYnAuc3VwYWJhc2UuY28vYXV0aC92MSIsInN1YiI6ImJkZWZhYzgxLTJiZDEtNDRkMS1iNWVkLTdhYmVkYjk2Y2NjZSIsImVtYWlsIjoiaW5mb0ByZWZpbmUuZGV2IiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCJ9LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJwYXNzd29yZCIsInRpbWVzdGFtcCI6MTcxNDAzNTQ5NX1dLCJzZXNzaW9uX2lkIjoiY2NjMWUzODEtNmFkYS00OTdkLWIxYjAtOWM4ZmJjNWQwYWZmIiwiaXNfYW5vbnltb3VzIjpmYWxzZX0.yVJ6lWNwdQCsbPsP5tfJk7Xjtx2bHRBaiyaox6KcMX0",
token_type: "bearer",
expires_in: 3600,
expires_at: 1714039095,
refresh_token: "R0tQR-e2RgQQdsS7OTMCWQ",
user: {
id: "bdefac81-2bd1-44d1-b5ed-7abedb96ccce",
aud: "authenticated",
role: "authenticated",
email: "info@refine.dev",
email_confirmed_at: "2021-09-08T11:09:24.284171Z",
phone: "",
confirmation_sent_at: "2021-09-08T11:08:06.793257Z",
confirmed_at: "2021-09-08T11:09:24.284171Z",
recovery_sent_at: "2024-02-04T09:33:53.383988Z",
last_sign_in_at: "2024-04-25T08:58:15.046729193Z",
app_metadata: { provider: "email" },
user_metadata: {},
identities: [
{
identity_id: "6b8dcf5b-f068-401b-95ae-ddd93d771b74",
id: "bdefac81-2bd1-44d1-b5ed-7abedb96ccce",
user_id: "bdefac81-2bd1-44d1-b5ed-7abedb96ccce",
identity_data: {
email: "info@refine.dev",
sub: "bdefac81-2bd1-44d1-b5ed-7abedb96ccce",
},
provider: "email",
last_sign_in_at: "2022-11-25T00:00:00Z",
created_at: "2022-11-25T00:00:00Z",
updated_at: "2022-11-25T00:00:00Z",
email: "info@refine.dev",
},
],
created_at: "2021-09-08T11:08:06.789274Z",
updated_at: "2024-04-25T08:58:15.04881Z",
is_anonymous: false,
},
},
[
"Date",
"Thu, 25 Apr 2024 08:58:15 GMT",
"Content-Type",
"application/json",
"Transfer-Encoding",
"chunked",
"Connection",
"close",
"CF-Ray",
"879d21512ac6519b-IST",
"CF-Cache-Status",
"DYNAMIC",
"Access-Control-Allow-Origin",
"*",
"Set-Cookie",
"sb-access-token=eyJhbGciOiJIUzI1NiIsImtpZCI6IldGWnFuOWt6bnBJZTIvL2wiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzE0MDM5MDk1LCJpYXQiOjE3MTQwMzU0OTUsImlzcyI6Imh0dHBzOi8vaXdkZnp2ZnFidG9rcWV0bWJtYnAuc3VwYWJhc2UuY28vYXV0aC92MSIsInN1YiI6ImJkZWZhYzgxLTJiZDEtNDRkMS1iNWVkLTdhYmVkYjk2Y2NjZSIsImVtYWlsIjoiaW5mb0ByZWZpbmUuZGV2IiwicGhvbmUiOiIiLCJhcHBfbWV0YWRhdGEiOnsicHJvdmlkZXIiOiJlbWFpbCJ9LCJ1c2VyX21ldGFkYXRhIjp7fSwicm9sZSI6ImF1dGhlbnRpY2F0ZWQiLCJhYWwiOiJhYWwxIiwiYW1yIjpbeyJtZXRob2QiOiJwYXNzd29yZCIsInRpbWVzdGFtcCI6MTcxNDAzNTQ5NX1dLCJzZXNzaW9uX2lkIjoiY2NjMWUzODEtNmFkYS00OTdkLWIxYjAtOWM4ZmJjNWQwYWZmIiwiaXNfYW5vbnltb3VzIjpmYWxzZX0.yVJ6lWNwdQCsbPsP5tfJk7Xjtx2bHRBaiyaox6KcMX0; Path=/; Expires=Fri, 26 Apr 2024 08:58:15 GMT; Max-Age=86400; HttpOnly; Secure",
"Strict-Transport-Security",
"max-age=15552000; includeSubDomains",
"Vary",
"Accept-Encoding, Origin",
"Via",
"kong/2.8.1",
"sb-gateway-version",
"1",
"Set-Cookie",
"sb-refresh-token=R0tQR-e2RgQQdsS7OTMCWQ; Path=/; Expires=Fri, 26 Apr 2024 08:58:15 GMT; Max-Age=86400; HttpOnly; Secure",
"x-kong-proxy-latency",
"1",
"x-kong-upstream-latency",
"90",
"Server",
"cloudflare",
"alt-svc",
'h3=":443"; ma=86400',
],
);

nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
encodedQueryParams: true,
})
Expand All @@ -8,64 +98,85 @@ nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
slug: "foo-bar",
content: "bar",
categoryId: 2,
image: {},
})
.matchHeader("Prefer", "return=representation")
.query({ select: "*" })
.query({ select: "%2A" })
.reply(
201,
[
{
id: 33,
id: 12893,
title: "foo",
slug: "foo-bar",
createdAt: "2021-09-06T09:50:17.716058+00:00",
createdAt: "2024-04-25T08:58:15.561287+00:00",
content: "bar",
categoryId: 2,
image: {},
images: null,
},
],
[
"Date",
"Thu, 25 Apr 2024 08:58:15 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Transfer-Encoding",
"chunked",
"Connection",
"close",
"Date",
"Mon, 06 Sep 2021 09:50:17 GMT",
"Server",
"postgrest/8.0.0",
"Location",
"/posts?id=eq.33",
"Content-Range",
"*/*",
"Content-Profile",
"public",
"vary",
"Origin",
"CF-Ray",
"879d2155cf286970-IST",
"CF-Cache-Status",
"DYNAMIC",
"Access-Control-Allow-Origin",
"*",
"X-Kong-Upstream-Latency",
"4",
"X-Kong-Proxy-Latency",
"1",
"Strict-Transport-Security",
"max-age=15552000; includeSubDomains",
"Via",
"kong/2.2.1",
"kong/2.8.1",
"content-profile",
"public",
"sb-gateway-version",
"1",
"x-kong-proxy-latency",
"3",
"x-kong-upstream-latency",
"7",
"Vary",
"Accept-Encoding",
"Server",
"cloudflare",
"alt-svc",
'h3=":443"; ma=86400',
],
);

nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
encodedQueryParams: true,
})
.post("/rest/v1/products", { name: "foo" })
.post("/rest/v1/posts", {
title: "foo",
slug: "foo-bar",
content: "bar",
categoryId: 2,
})
.query({ select: "%2A" })
.reply(
201,
[{ id: 19, name: "foo" }],
[
{
id: 12894,
title: "foo",
slug: "foo-bar",
createdAt: "2024-04-25T08:58:15.88472+00:00",
content: "bar",
categoryId: 2,
images: null,
},
],
[
"Date",
"Tue, 23 Jan 2024 11:54:21 GMT",
"Thu, 25 Apr 2024 08:58:15 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Transfer-Encoding",
Expand All @@ -75,23 +186,23 @@ nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
"Content-Range",
"*/*",
"CF-Ray",
"849fd76c0a25733a-BUD",
"879d21585813724e-IST",
"CF-Cache-Status",
"DYNAMIC",
"Access-Control-Allow-Origin",
"*",
"Strict-Transport-Security",
"max-age=2592000; includeSubDomains",
"max-age=15552000; includeSubDomains",
"Via",
"kong/2.8.1",
"Content-Profile",
"content-profile",
"public",
"sb-gateway-version",
"1",
"X-Kong-Proxy-Latency",
"1",
"X-Kong-Upstream-Latency",
"6",
"x-kong-proxy-latency",
"0",
"x-kong-upstream-latency",
"7",
"Vary",
"Accept-Encoding",
"Server",
Expand All @@ -104,8 +215,8 @@ nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
encodedQueryParams: true,
})
.post("/rest/v1/products", {})
.query({ select: "*" })
.post("/rest/v1/posts", {})
.query({ select: "%2A" })
.reply(
406,
{
Expand All @@ -116,29 +227,29 @@ nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
},
[
"Date",
"Tue, 23 Jan 2024 12:06:17 GMT",
"Thu, 25 Apr 2024 08:58:16 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Transfer-Encoding",
"chunked",
"Connection",
"close",
"CF-Ray",
"849fe8e499a068bb-BUD",
"879d2159d8847212-IST",
"CF-Cache-Status",
"DYNAMIC",
"Access-Control-Allow-Origin",
"*",
"Strict-Transport-Security",
"max-age=2592000; includeSubDomains",
"max-age=15552000; includeSubDomains",
"Via",
"kong/2.8.1",
"sb-gateway-version",
"1",
"X-Kong-Proxy-Latency",
"0",
"X-Kong-Upstream-Latency",
"x-kong-proxy-latency",
"1",
"x-kong-upstream-latency",
"0",
"Vary",
"Accept-Encoding",
"Server",
Expand All @@ -147,3 +258,41 @@ nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
'h3=":443"; ma=86400',
],
);

nock("https://iwdfzvfqbtokqetmbmbp.supabase.co:443", {
encodedQueryParams: true,
})
.post("/auth/v1/logout")
.query({ scope: "global" })
.reply(204, "", [
"Date",
"Thu, 25 Apr 2024 08:58:16 GMT",
"Connection",
"close",
"CF-Ray",
"879d215b9ec65184-IST",
"CF-Cache-Status",
"DYNAMIC",
"Access-Control-Allow-Origin",
"*",
"Set-Cookie",
"sb-access-token=; Path=/; Expires=Wed, 24 Apr 2024 22:58:16 GMT; Max-Age=0; HttpOnly; Secure",
"Strict-Transport-Security",
"max-age=15552000; includeSubDomains",
"Vary",
"Origin, Accept-Encoding",
"Via",
"kong/2.8.1",
"sb-gateway-version",
"1",
"Set-Cookie",
"sb-refresh-token=; Path=/; Expires=Wed, 24 Apr 2024 22:58:16 GMT; Max-Age=0; HttpOnly; Secure",
"x-kong-proxy-latency",
"1",
"x-kong-upstream-latency",
"11",
"Server",
"cloudflare",
"alt-svc",
'h3=":443"; ma=86400',
]);
25 changes: 19 additions & 6 deletions packages/supabase/test/create/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import supabaseClient from "../supabaseClient";
import "./index.mock";

describe("create", () => {
beforeAll(async () => {
await supabaseClient.auth.signInWithPassword({
email: "info@refine.dev",
password: "refine-supabase",
});
});

afterAll(async () => {
await supabaseClient.auth.signOut();
});

it("correct response with `select`", async () => {
const { data } = await dataProvider(supabaseClient).create({
resource: "posts",
Expand All @@ -11,14 +22,13 @@ describe("create", () => {
slug: "foo-bar",
content: "bar",
categoryId: 2,
image: {},
},
meta: {
select: "*",
},
});

expect(data["id"]).toEqual(33);
expect(data["id"]).toEqual(12893);
expect(data["title"]).toEqual("foo");
expect(data["slug"]).toEqual("foo-bar");
expect(data["content"]).toEqual("bar");
Expand All @@ -27,21 +37,24 @@ describe("create", () => {

it("should change schema", async () => {
const { data } = await dataProvider(supabaseClient).create({
resource: "products",
resource: "posts",
variables: {
name: "foo",
title: "foo",
slug: "foo-bar",
content: "bar",
categoryId: 2,
},
meta: {
schema: "public",
select: "*",
},
});

expect(data["name"]).toEqual("foo");
expect(data["title"]).toEqual("foo");

try {
await dataProvider(supabaseClient).create({
resource: "products",
resource: "posts",
variables: {},
meta: {
schema: "private",
Expand Down
Loading

0 comments on commit 9675681

Please sign in to comment.