Skip to content

Commit 7d45c10

Browse files
authored
feat(core): create multi custom domains (#7763)
1 parent bc0d462 commit 7d45c10

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

packages/core/src/routes/domain.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ describe('domain routes', () => {
7272
expect(response.body.domain).toEqual('test.com');
7373
});
7474

75-
it('POST /domains should fail when there is already a domain', async () => {
76-
await expect(
77-
domainRequest.post('/domains').send({ domain: mockDomain.domain })
78-
).resolves.toHaveProperty('status', 422);
75+
it('POST /domains allows creating multiple domains', async () => {
76+
const response = await domainRequest.post('/domains').send({ domain: 'another.com' });
77+
expect(response.status).toEqual(201);
78+
expect(addDomain).toBeCalledWith('another.com');
7979
});
8080

8181
it('DELETE /domains/:id', async () => {

packages/core/src/routes/domain.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import RequestError from '#src/errors/RequestError/index.js';
66
import koaGuard from '#src/middleware/koa-guard.js';
77
import assertThat from '#src/utils/assert-that.js';
88

9+
import { EnvSet } from '../env-set/index.js';
10+
911
import type { ManagementApiRouter, RouterInitArgs } from './types.js';
1012

1113
export default function domainRoutes<T extends ManagementApiRouter>(
@@ -75,14 +77,16 @@ export default function domainRoutes<T extends ManagementApiRouter>(
7577
status: [201, 422, 400],
7678
}),
7779
async (ctx, next) => {
78-
const existingDomains = await findAllDomains();
79-
assertThat(
80-
existingDomains.length === 0,
81-
new RequestError({
82-
code: 'domain.limit_to_one_domain',
83-
status: 422,
84-
})
85-
);
80+
if (!EnvSet.values.isDevFeaturesEnabled) {
81+
const existingDomains = await findAllDomains();
82+
assertThat(
83+
existingDomains.length === 0,
84+
new RequestError({
85+
code: 'domain.limit_to_one_domain',
86+
status: 422,
87+
})
88+
);
89+
}
8690

8791
// Throw 400 error if domain is invalid
8892
const syncedDomain = await addDomain(ctx.guard.body.domain);

packages/integration-tests/src/tests/api/domains.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HTTPError } from 'ky';
22

33
import { createDomain, deleteDomain, getDomain, getDomains } from '#src/api/domain.js';
4-
import { generateDomain } from '#src/utils.js';
4+
import { devFeatureDisabledTest, devFeatureTest, generateDomain } from '#src/utils.js';
55

66
describe('domains', () => {
77
afterEach(async () => {
@@ -23,13 +23,24 @@ describe('domains', () => {
2323
expect(domain.domain).toBe(domainName);
2424
});
2525

26-
it('should fail when already has a domain', async () => {
26+
// Todo: @xiaoyijun [Multiple Custom Domains] Remove legacy tests
27+
devFeatureDisabledTest.it('should fail when already has a domain', async () => {
2728
await createDomain();
2829

2930
const response = await createDomain().catch((error: unknown) => error);
3031
expect(response instanceof HTTPError && response.response.status).toBe(422);
3132
});
3233

34+
// Todo: @xiaoyijun [Multiple Custom Domains] Remove legacy tests
35+
devFeatureTest.it('should create multiple domains', async () => {
36+
const first = await createDomain();
37+
const second = await createDomain();
38+
39+
expect(first.id).toBeTruthy();
40+
expect(second.id).toBeTruthy();
41+
expect(first.id).not.toEqual(second.id);
42+
});
43+
3344
it('should get domain detail successfully', async () => {
3445
const createdDomain = await createDomain();
3546
const domain = await getDomain(createdDomain.id);

0 commit comments

Comments
 (0)