Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable domain edition only on turbo and legacy spaces #488

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/writer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export async function verify(body): Promise<any> {
const isAdmin = admins.includes(body.address.toLowerCase());
const newAdmins = (msg.payload.admins || []).map(admin => admin.toLowerCase());

if (msg.payload.domain && !space?.turbo && !space?.domain) {
return Promise.reject('domain is a turbo feature only');
}

const anotherSpaceWithDomain = (
await db.queryAsync('SELECT 1 FROM spaces WHERE domain = ? AND id != ? LIMIT 1', [
msg.payload.domain,
Expand Down
66 changes: 65 additions & 1 deletion test/unit/writer/settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SpaceSchema from '@snapshot-labs/snapshot.js/src/schemas/space.json';
import { verify } from '../../../src/writer/settings';
import { spacesGetSpaceFixtures } from '../../fixtures/space';
import input from '../../fixtures/writer-payload/space.json';
import SpaceSchema from '@snapshot-labs/snapshot.js/src/schemas/space.json';

function editedInput(payload = {}) {
const result = { ...input, msg: JSON.parse(input.msg) };
Expand Down Expand Up @@ -105,6 +105,70 @@ describe('writer/settings', () => {
)
).rejects.toContain('wrong space format');
});

describe('when the space has an existing custom domain', () => {
it('accepts a new domain for non-turbo spaces', () => {
mockGetSpace.mockResolvedValueOnce({
...spacesGetSpaceFixtures,
turbo: false,
domain: 'test.com'
});
return expect(
verify(
editedInput({
domain: 'test2.com'
})
)
).resolves.toBeUndefined();
});

it('accepts a new domain for turbo spaces', () => {
mockGetSpace.mockResolvedValueOnce({
...spacesGetSpaceFixtures,
turbo: true,
domain: 'test.com'
});
return expect(
verify(
editedInput({
domain: 'test2.com'
})
)
).resolves.toBeUndefined();
});
});

describe('when the space does not have an existing custom domain', () => {
it('rejects a new domain for non-turbo spaces', () => {
mockGetSpace.mockResolvedValueOnce({
...spacesGetSpaceFixtures,
turbo: false,
domain: undefined
});
return expect(
verify(
editedInput({
domain: 'test2.com'
})
)
).rejects.toContain('domain is a turbo feature only');
});

it('accepts a new domain for turbo spaces', () => {
mockGetSpace.mockResolvedValueOnce({
...spacesGetSpaceFixtures,
turbo: true,
domain: undefined
});
return expect(
verify(
editedInput({
domain: 'test2.com'
})
)
).resolves.toBeUndefined();
});
});
});

describe('on valid data', () => {
Expand Down
Loading