@webstudio-is/postgrest 0.252.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +51 -0
- package/package.json +29 -0
- package/playground/domains.ts +54 -0
- package/playground/pnpm-playground +8 -0
- package/src/__generated__/db-types.ts +1176 -0
- package/src/index.server.ts +16 -0
- package/supabase/SQL-TESTS-AI.md +161 -0
- package/supabase/tests/cleanup-builds.sql +227 -0
- package/supabase/tests/latest-builds-domains.sql +516 -0
- package/supabase/tests/latest-builds-projects.sql +808 -0
- package/supabase/tests/project-domains.sql +77 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
BEGIN;
|
|
2
|
+
SET LOCAL search_path = pgtap, public;
|
|
3
|
+
-- Initialize the testing environment without planning any specific number of tests
|
|
4
|
+
-- We are using SELECT no_plan() because we don't specify the exact number of tests upfront.
|
|
5
|
+
SELECT no_plan();
|
|
6
|
+
|
|
7
|
+
-- Insert a new user into the User table for the project ownership
|
|
8
|
+
-- We're inserting user_1 as the user for the test projects
|
|
9
|
+
INSERT INTO "public"."User" ("id", "createdAt", "email", "username")
|
|
10
|
+
VALUES
|
|
11
|
+
('user_1', '2023-01-01 00:00:00+00', 'user1@517cce32-9af3-example.com', 'user1');
|
|
12
|
+
|
|
13
|
+
-- Insert test projects into the Project table
|
|
14
|
+
-- project_1 and project_2 belong to user_1 and are not deleted (isDeleted = false)
|
|
15
|
+
INSERT INTO "Project" (id, title, domain, "userId", "isDeleted") VALUES
|
|
16
|
+
('project_1', 'Test Project 1', '517cce32-9af3-testproject1.com', 'user_1', false),
|
|
17
|
+
('project_2', 'Test Project 1', '517cce32-9af3-testproject2.com', 'user_1', false);
|
|
18
|
+
|
|
19
|
+
-- Insert test domains into the Domain table
|
|
20
|
+
-- We are inserting two domains: 517cce32-9af3-example.com and 517cce32-9af3-example.org with different statuses
|
|
21
|
+
INSERT INTO "Domain" (id, domain, status, "txtRecord") VALUES
|
|
22
|
+
('domain_1', '517cce32-9af3-example.com', 'INITIALIZING', 'txtRecord1'),
|
|
23
|
+
('domain_2', '517cce32-9af3-example.org', 'ACTIVE', 'txtRecord21');
|
|
24
|
+
|
|
25
|
+
-- Insert test data into the ProjectDomain table
|
|
26
|
+
-- Mapping domains to projects, project_1 has two domains, project_2 has one domain
|
|
27
|
+
-- Note the different TXT records in ProjectDomain
|
|
28
|
+
INSERT INTO "ProjectDomain" ("projectId", "domainId", "txtRecord", "cname") VALUES
|
|
29
|
+
('project_1', 'domain_1', 'txtRecord1', 'cname1'),
|
|
30
|
+
('project_1', 'domain_2', 'txtRecord22', 'cname2'),
|
|
31
|
+
('project_2', 'domain_1', 'txtRecord3', 'cname3');
|
|
32
|
+
|
|
33
|
+
-- Test case 1: Verify that domainsVirtual returns correct values for project_1
|
|
34
|
+
-- Compare the result of the domainsVirtual function with an expected result set.
|
|
35
|
+
-- Project_1 is expected to return two domains with statuses, TXT records, and verification status
|
|
36
|
+
SELECT results_eq(
|
|
37
|
+
$$
|
|
38
|
+
SELECT domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified
|
|
39
|
+
FROM "domainsVirtual"(
|
|
40
|
+
(SELECT (p.*)::"Project" FROM "Project" p WHERE p.id = 'project_1' ORDER BY p.id)
|
|
41
|
+
)
|
|
42
|
+
$$,
|
|
43
|
+
$$
|
|
44
|
+
SELECT * FROM (
|
|
45
|
+
VALUES
|
|
46
|
+
('517cce32-9af3-example.com','INITIALIZING'::"DomainStatus",NULL,E'txtRecord1',E'txtRecord1',TRUE), -- Verified domain (TXT records match)
|
|
47
|
+
('517cce32-9af3-example.org','ACTIVE'::"DomainStatus",NULL,E'txtRecord21',E'txtRecord22',FALSE) -- Not verified domain (TXT records do not match)
|
|
48
|
+
) AS expected(domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified)
|
|
49
|
+
ORDER BY "domain"
|
|
50
|
+
$$,
|
|
51
|
+
'Test case 1: domainsVirtual should return correct results for project_1'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
-- Test case 2: Verify that domainsVirtual returns correct values for project_2
|
|
55
|
+
-- Project_2 is expected to return one domain with its corresponding status, TXT records, and verification status
|
|
56
|
+
SELECT results_eq(
|
|
57
|
+
$$
|
|
58
|
+
SELECT domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified
|
|
59
|
+
FROM "domainsVirtual"(
|
|
60
|
+
(SELECT (p.*)::"Project" FROM "Project" p WHERE p.id = 'project_2' ORDER BY p.id)
|
|
61
|
+
)
|
|
62
|
+
$$,
|
|
63
|
+
$$
|
|
64
|
+
SELECT * FROM (
|
|
65
|
+
VALUES
|
|
66
|
+
('517cce32-9af3-example.com','INITIALIZING'::"DomainStatus",NULL,E'txtRecord1',E'txtRecord3',FALSE) -- Not verified domain (TXT records do not match)
|
|
67
|
+
) AS expected(domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified)
|
|
68
|
+
ORDER BY "domain"
|
|
69
|
+
$$,
|
|
70
|
+
'Test case 2: domainsVirtual should return correct results for project_2'
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
-- Finish the test by calling the finish() function, which outputs the test summary
|
|
74
|
+
SELECT finish();
|
|
75
|
+
|
|
76
|
+
-- Rollback the transaction to ensure no changes are persisted in the database
|
|
77
|
+
ROLLBACK;
|
package/tsconfig.json
ADDED