mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-04 22:31:33 +09:00
## Description closes #2644 - [x] - Merge this https://github.com/webstudio-is/webstudio/pull/4156 into this PR - If the user has no custom domains: - [x] Checkbox for Pro users is not shown. - [x] Checkbox for Free users is shown but disabled (Tooltip enabled). - If the user has custom domains: - No Pro: - [x] Checkboxes are shown disabled with Tooltips. - Pro: - Users can select any checkbox (no Tooltips). - Current indexing logic: - If a user has custom domain(s), upon publishing, the `*.wstd.io` domain will receive the meta tag: ```html <meta name="robots" content="noindex, nofollow"> ``` - [x] - Fix example.com in tests (NEXT PR #4156) - [ ] - saas cleanup should be changed (we need to preserve latest build by domain now) (NEXT PR) - [x] - Disable Publish Button if no checkboxes are selected - "With the Pro, you’ll gain the ability to publish to each domain independently!" <img width="477" alt="image" src="https://github.com/user-attachments/assets/105577e5-318f-4146-a3eb-38c2117f6f79"> ## Steps for reproduction ### Non Pro - Login as a new non Pro User `pass:vaska@pupkin.ru` - Create a new Project, Click Publish. Expect Disabled Checkbox with Tolltip is visible. Publish is Enabled. <img width="445" alt="image" src="https://github.com/user-attachments/assets/e48654af-1969-4f96-b048-a3fa72303b8f"> - Publish, check it published. - Add custom domain, Publish, check both are published. ### Pro - Login as a Pro User `pass` - Open new Project. Expect No checkbox. One wstd domain. <img width="351" alt="image" src="https://github.com/user-attachments/assets/c62f9ae5-669a-46ad-a2f2-32ba333068f9"> - Publish. Expect it published. - Add domain. See checkboxes visible after domain activated. - Publish. Expect both published. - Uncheck checkboxes, see publish button disabled. See it has tooltip. ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
228 lines
7.6 KiB
PL/PgSQL
228 lines
7.6 KiB
PL/PgSQL
BEGIN;
|
|
SET LOCAL search_path = pgtap, public;
|
|
-- Initialize the testing environment without planning any specific number of tests
|
|
-- We are using SELECT no_plan() because we don't specify the exact number of tests upfront.
|
|
SELECT no_plan();
|
|
|
|
-- =========================================
|
|
-- Setup: Insert initial data for Users, Projects, Domains, ProjectDomains, and Builds
|
|
-- =========================================
|
|
|
|
-- Insert a user into the "User" table
|
|
INSERT INTO "public"."User" ("id", "createdAt", "email", "username")
|
|
VALUES
|
|
('user1', '2023-01-01 00:00:00+00', 'user1@517cce32-9af3-example.com', 'user1');
|
|
|
|
-- Insert projects associated with the user into the "Project" table
|
|
INSERT INTO "public"."Project" ("id", "title", "domain", "userId", "isDeleted", "createdAt")
|
|
VALUES
|
|
('project1', 'Project One', '517cce32-9af3-project1-domain1', 'user1', false, '2023-01-01 00:00:00+00'),
|
|
('project2', 'Project Two', '517cce32-9af3-project2-domain1', 'user1', false, '2023-01-01 00:00:00+00');
|
|
|
|
-- Insert custom domains into the "Domain" table
|
|
INSERT INTO "public"."Domain" ("id", "domain", "createdAt", "status", "updatedAt")
|
|
VALUES
|
|
('project-1-custom-domain-1', '517cce32-9af3-project-1-custom-domain-1.com', '2023-01-01 00:00:00+00', 'INITIALIZING', '2023-01-01 00:00:00+00'),
|
|
('project-1-custom-domain-2', '517cce32-9af3-project-1-custom-domain-2.com', '2023-01-01 00:00:00+00', 'INITIALIZING', '2023-01-01 00:00:00+00'),
|
|
('project-2-custom-domain-1', '517cce32-9af3-project-2-custom-domain-1.com', '2023-01-01 00:00:00+00', 'INITIALIZING', '2023-01-01 00:00:00+00'),
|
|
('project-2-custom-domain-2', '517cce32-9af3-project-2-custom-domain-2.com', '2023-01-01 00:00:00+00', 'INITIALIZING', '2023-01-01 00:00:00+00');
|
|
|
|
-- Establish relationships between projects and custom domains in the "ProjectDomain" table
|
|
INSERT INTO "public"."ProjectDomain" ("projectId", "domainId", "createdAt", "txtRecord", "cname")
|
|
VALUES
|
|
('project1', 'project-1-custom-domain-1', '2023-01-01 00:00:00+00', 'txtRecord1', 'cname1'),
|
|
('project1', 'project-1-custom-domain-2', '2023-01-01 00:00:00+00', 'txtRecord2', 'cname2'),
|
|
('project2', 'project-2-custom-domain-1', '2023-01-01 00:00:00+00', 'p2-txtRecord1', 'cname1'),
|
|
('project2', 'project-2-custom-domain-2', '2023-01-01 00:00:00+00', 'p2-txtRecord2', 'cname2');
|
|
|
|
-- Insert initial builds into the "Build" table
|
|
INSERT INTO "public"."Build" (
|
|
"id",
|
|
"createdAt",
|
|
"pages",
|
|
"projectId",
|
|
"deployment",
|
|
"updatedAt",
|
|
"publishStatus"
|
|
)
|
|
VALUES
|
|
-- Development Build for Project1
|
|
(
|
|
'build1-development',
|
|
'1990-01-01 00:00:00+00',
|
|
'home',
|
|
'project1',
|
|
NULL,
|
|
'1990-01-01 00:00:00+00',
|
|
'PENDING'
|
|
),
|
|
-- Development Build for Project2
|
|
(
|
|
'project2-build1-development',
|
|
'1990-01-01 00:00:00+00',
|
|
'home',
|
|
'project2',
|
|
NULL,
|
|
'1990-01-01 00:00:00+00',
|
|
'PENDING'
|
|
),
|
|
-- Custom Domain Build for Project2
|
|
(
|
|
'project2-build1-for-custom-domain-1',
|
|
'1990-01-02 00:00:00+00',
|
|
'home',
|
|
'project2',
|
|
'{"domains": ["517cce32-9af3-project-2-custom-domain-1.com"]}'::text,
|
|
'1990-01-02 00:00:00+00',
|
|
'PUBLISHED'
|
|
),
|
|
-- Project Domain Build for Project2
|
|
(
|
|
'project2-build1-for-project-domain-1',
|
|
'1990-01-01 00:00:00+00',
|
|
'home',
|
|
'project2',
|
|
'{"domains": ["517cce32-9af3-project2-domain1"]}'::text,
|
|
'1990-01-01 00:00:00+00',
|
|
'PUBLISHED'
|
|
),
|
|
-- Custom Domain Build for Project1
|
|
(
|
|
'build1-for-custom-domain-1',
|
|
'1990-01-02 00:00:00+00',
|
|
'home',
|
|
'project1',
|
|
'{"domains": ["517cce32-9af3-project-1-custom-domain-1.com"]}'::text,
|
|
'1990-01-02 00:00:00+00',
|
|
'PUBLISHED'
|
|
),
|
|
-- Project Domain Build for Project1
|
|
(
|
|
'build1-for-project-domain-1',
|
|
'1990-01-01 00:00:00+00',
|
|
'home',
|
|
'project1',
|
|
'{"domains": ["517cce32-9af3-project1-domain1"]}'::text,
|
|
'1990-01-01 00:00:00+00',
|
|
'PUBLISHED'
|
|
);
|
|
|
|
-- =========================================
|
|
-- Test 1: Verify that initial cleanup does not clean any builds
|
|
-- =========================================
|
|
|
|
-- Run the database cleanup function for builds created in 1990
|
|
SELECT database_cleanup('1990-01-01 00:00:00', '1990-12-31 23:59:59');
|
|
|
|
-- Assert that no builds have been cleaned up initially
|
|
SELECT is(
|
|
(SELECT count(*)::integer FROM "Build" WHERE "createdAt" BETWEEN '1990-01-01' AND '1990-12-31' AND "isCleaned" = TRUE),
|
|
0,
|
|
'Test 1: No builds should be cleaned up on initial cleanup'
|
|
);
|
|
|
|
-- =========================================
|
|
-- Test 2: Insert a new project domain build and verify cleanup
|
|
-- =========================================
|
|
|
|
-- Insert a new build for the project domain
|
|
INSERT INTO "public"."Build" (
|
|
"id",
|
|
"createdAt",
|
|
"pages",
|
|
"projectId",
|
|
"deployment",
|
|
"updatedAt",
|
|
"publishStatus"
|
|
)
|
|
VALUES
|
|
-- New Project Domain Build for Project1
|
|
(
|
|
'build2-for-project-domain-1',
|
|
'1990-01-02 00:00:00+00', -- A later date than the previous build
|
|
'home',
|
|
'project1',
|
|
'{"domains": ["517cce32-9af3-project1-domain1"]}'::text,
|
|
'1990-01-02 00:00:00+00',
|
|
'PUBLISHED'
|
|
);
|
|
|
|
-- Run the database cleanup function again
|
|
SELECT database_cleanup('1990-01-01 00:00:00', '1990-12-31 23:59:59');
|
|
|
|
-- Assert that one build has been cleaned (the previous project domain build)
|
|
SELECT is(
|
|
(SELECT count(*)::integer FROM "Build" WHERE "createdAt" BETWEEN '1990-01-01' AND '1990-12-31' AND "isCleaned" = TRUE),
|
|
1,
|
|
'Test 2: Previous project domain build should be cleaned up after new build is published'
|
|
);
|
|
|
|
-- Assert that the specific build cleaned is 'build1-for-project-domain-1'
|
|
SELECT is(
|
|
(SELECT id FROM "Build" WHERE "createdAt" BETWEEN '1990-01-01' AND '1990-12-31' AND "isCleaned" = TRUE),
|
|
'build1-for-project-domain-1',
|
|
'Test 2: Build "build1-for-project-domain-1" should be marked as cleaned'
|
|
);
|
|
|
|
-- =========================================
|
|
-- Test 3: Insert a new custom domain build and verify cleanup
|
|
-- =========================================
|
|
|
|
-- Insert a new build for the custom domain
|
|
INSERT INTO "public"."Build" (
|
|
"id",
|
|
"createdAt",
|
|
"pages",
|
|
"projectId",
|
|
"deployment",
|
|
"updatedAt",
|
|
"publishStatus"
|
|
)
|
|
VALUES
|
|
-- New Custom Domain Build for Project1
|
|
(
|
|
'build2-for-custom-domain-1',
|
|
'1990-01-03 00:00:00+00', -- A later date than the previous build
|
|
'home',
|
|
'project1',
|
|
'{"domains": ["517cce32-9af3-project-1-custom-domain-1.com"]}'::text,
|
|
'1990-01-03 00:00:00+00',
|
|
'PUBLISHED'
|
|
);
|
|
|
|
-- Run the database cleanup function again
|
|
SELECT database_cleanup('1990-01-01 00:00:00', '1990-12-31 23:59:59');
|
|
|
|
-- Assert that two builds have been cleaned (the previous project domain and custom domain builds)
|
|
SELECT is(
|
|
(SELECT count(*)::integer FROM "Build" WHERE "createdAt" BETWEEN '1990-01-01' AND '1990-12-31' AND "isCleaned" = TRUE),
|
|
2,
|
|
'Test 3: Previous custom domain build should be cleaned up after new build is published'
|
|
);
|
|
|
|
-- Assert that the builds cleaned are 'build1-for-custom-domain-1' and 'build1-for-project-domain-1'
|
|
SELECT results_eq(
|
|
$$
|
|
SELECT id FROM "Build" WHERE "createdAt" BETWEEN '1990-01-01' AND '1990-12-31' AND "isCleaned" = TRUE ORDER BY id
|
|
$$,
|
|
$$
|
|
SELECT * FROM (
|
|
VALUES
|
|
('build1-for-custom-domain-1'),
|
|
('build1-for-project-domain-1')
|
|
) AS expected(id)
|
|
ORDER BY "id"
|
|
$$,
|
|
'Test 3: Builds "build1-for-custom-domain-1" and "build1-for-project-domain-1" should be marked as cleaned'
|
|
);
|
|
|
|
-- =========================================
|
|
-- Finish the test
|
|
-- =========================================
|
|
|
|
-- Finish the test by calling the finish() function, which outputs the test summary
|
|
SELECT finish();
|
|
|
|
-- Rollback the transaction to ensure no changes are persisted in the database
|
|
ROLLBACK;
|