Files
webstudio/packages/postgrest/supabase/tests/project-domains.sql
Ivan Starkov 6ba6fc5ce8 feat: Preview by publishing to subdomain only aka staging (#4143)
## 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
2024-09-25 10:24:23 +03:00

77 lines
3.7 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();
-- Insert a new user into the User table for the project ownership
-- We're inserting user_1 as the user for the test projects
INSERT INTO "public"."User" ("id", "createdAt", "email", "username")
VALUES
('user_1', '2023-01-01 00:00:00+00', 'user1@517cce32-9af3-example.com', 'user1');
-- Insert test projects into the Project table
-- project_1 and project_2 belong to user_1 and are not deleted (isDeleted = false)
INSERT INTO "Project" (id, title, domain, "userId", "isDeleted") VALUES
('project_1', 'Test Project 1', '517cce32-9af3-testproject1.com', 'user_1', false),
('project_2', 'Test Project 1', '517cce32-9af3-testproject2.com', 'user_1', false);
-- Insert test domains into the Domain table
-- We are inserting two domains: 517cce32-9af3-example.com and 517cce32-9af3-example.org with different statuses
INSERT INTO "Domain" (id, domain, status, "txtRecord") VALUES
('domain_1', '517cce32-9af3-example.com', 'INITIALIZING', 'txtRecord1'),
('domain_2', '517cce32-9af3-example.org', 'ACTIVE', 'txtRecord21');
-- Insert test data into the ProjectDomain table
-- Mapping domains to projects, project_1 has two domains, project_2 has one domain
-- Note the different TXT records in ProjectDomain
INSERT INTO "ProjectDomain" ("projectId", "domainId", "txtRecord", "cname") VALUES
('project_1', 'domain_1', 'txtRecord1', 'cname1'),
('project_1', 'domain_2', 'txtRecord22', 'cname2'),
('project_2', 'domain_1', 'txtRecord3', 'cname3');
-- Test case 1: Verify that domainsVirtual returns correct values for project_1
-- Compare the result of the domainsVirtual function with an expected result set.
-- Project_1 is expected to return two domains with statuses, TXT records, and verification status
SELECT results_eq(
$$
SELECT domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified
FROM "domainsVirtual"(
(SELECT (p.*)::"Project" FROM "Project" p WHERE p.id = 'project_1' ORDER BY p.id)
)
$$,
$$
SELECT * FROM (
VALUES
('517cce32-9af3-example.com','INITIALIZING'::"DomainStatus",NULL,E'txtRecord1',E'txtRecord1',TRUE), -- Verified domain (TXT records match)
('517cce32-9af3-example.org','ACTIVE'::"DomainStatus",NULL,E'txtRecord21',E'txtRecord22',FALSE) -- Not verified domain (TXT records do not match)
) AS expected(domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified)
ORDER BY "domain"
$$,
'Test case 1: domainsVirtual should return correct results for project_1'
);
-- Test case 2: Verify that domainsVirtual returns correct values for project_2
-- Project_2 is expected to return one domain with its corresponding status, TXT records, and verification status
SELECT results_eq(
$$
SELECT domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified
FROM "domainsVirtual"(
(SELECT (p.*)::"Project" FROM "Project" p WHERE p.id = 'project_2' ORDER BY p.id)
)
$$,
$$
SELECT * FROM (
VALUES
('517cce32-9af3-example.com','INITIALIZING'::"DomainStatus",NULL,E'txtRecord1',E'txtRecord3',FALSE) -- Not verified domain (TXT records do not match)
) AS expected(domain, status, error, "domainTxtRecord", "expectedTxtRecord", verified)
ORDER BY "domain"
$$,
'Test case 2: domainsVirtual should return correct results for project_2'
);
-- 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;