Skip to content

Commit bf2b8de

Browse files
wa0x6eChaituVR
andauthored
feat: enable domain edition only on turbo and legacy spaces (#488)
* feat: enable domain edition only on turbo and legacy spaces * Update src/writer/settings.ts Co-authored-by: Chaitanya <[email protected]> --------- Co-authored-by: Chaitanya <[email protected]>
1 parent 0776492 commit bf2b8de

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

src/writer/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ export async function verify(body): Promise<any> {
8282
const isAdmin = admins.includes(body.address.toLowerCase());
8383
const newAdmins = (msg.payload.admins || []).map(admin => admin.toLowerCase());
8484

85+
if (msg.payload.domain && !space?.turbo && !space?.domain) {
86+
return Promise.reject('domain is a turbo feature only');
87+
}
88+
8589
const anotherSpaceWithDomain = (
8690
await db.queryAsync('SELECT 1 FROM spaces WHERE domain = ? AND id != ? LIMIT 1', [
8791
msg.payload.domain,

test/unit/writer/settings.test.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import SpaceSchema from '@snapshot-labs/snapshot.js/src/schemas/space.json';
12
import { verify } from '../../../src/writer/settings';
23
import { spacesGetSpaceFixtures } from '../../fixtures/space';
34
import input from '../../fixtures/writer-payload/space.json';
4-
import SpaceSchema from '@snapshot-labs/snapshot.js/src/schemas/space.json';
55

66
function editedInput(payload = {}) {
77
const result = { ...input, msg: JSON.parse(input.msg) };
@@ -105,6 +105,70 @@ describe('writer/settings', () => {
105105
)
106106
).rejects.toContain('wrong space format');
107107
});
108+
109+
describe('when the space has an existing custom domain', () => {
110+
it('accepts a new domain for non-turbo spaces', () => {
111+
mockGetSpace.mockResolvedValueOnce({
112+
...spacesGetSpaceFixtures,
113+
turbo: false,
114+
domain: 'test.com'
115+
});
116+
return expect(
117+
verify(
118+
editedInput({
119+
domain: 'test2.com'
120+
})
121+
)
122+
).resolves.toBeUndefined();
123+
});
124+
125+
it('accepts a new domain for turbo spaces', () => {
126+
mockGetSpace.mockResolvedValueOnce({
127+
...spacesGetSpaceFixtures,
128+
turbo: true,
129+
domain: 'test.com'
130+
});
131+
return expect(
132+
verify(
133+
editedInput({
134+
domain: 'test2.com'
135+
})
136+
)
137+
).resolves.toBeUndefined();
138+
});
139+
});
140+
141+
describe('when the space does not have an existing custom domain', () => {
142+
it('rejects a new domain for non-turbo spaces', () => {
143+
mockGetSpace.mockResolvedValueOnce({
144+
...spacesGetSpaceFixtures,
145+
turbo: false,
146+
domain: undefined
147+
});
148+
return expect(
149+
verify(
150+
editedInput({
151+
domain: 'test2.com'
152+
})
153+
)
154+
).rejects.toContain('domain is a turbo feature only');
155+
});
156+
157+
it('accepts a new domain for turbo spaces', () => {
158+
mockGetSpace.mockResolvedValueOnce({
159+
...spacesGetSpaceFixtures,
160+
turbo: true,
161+
domain: undefined
162+
});
163+
return expect(
164+
verify(
165+
editedInput({
166+
domain: 'test2.com'
167+
})
168+
)
169+
).resolves.toBeUndefined();
170+
});
171+
});
108172
});
109173

110174
describe('on valid data', () => {

0 commit comments

Comments
 (0)