-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): Community+ enrollment (#10776)
- Loading branch information
Showing
20 changed files
with
585 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/@n8n/api-types/src/dto/license/__tests__/community-registered-request.dto.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { CommunityRegisteredRequestDto } from '../community-registered-request.dto'; | ||
|
||
describe('CommunityRegisteredRequestDto', () => { | ||
it('should fail validation for missing email', () => { | ||
const invalidRequest = {}; | ||
|
||
const result = CommunityRegisteredRequestDto.safeParse(invalidRequest); | ||
|
||
expect(result.success).toBe(false); | ||
expect(result.error?.issues[0]).toEqual( | ||
expect.objectContaining({ message: 'Required', path: ['email'] }), | ||
); | ||
}); | ||
|
||
it('should fail validation for an invalid email', () => { | ||
const invalidRequest = { | ||
email: 'invalid-email', | ||
}; | ||
|
||
const result = CommunityRegisteredRequestDto.safeParse(invalidRequest); | ||
|
||
expect(result.success).toBe(false); | ||
expect(result.error?.issues[0]).toEqual( | ||
expect.objectContaining({ message: 'Invalid email', path: ['email'] }), | ||
); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/@n8n/api-types/src/dto/license/community-registered-request.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { z } from 'zod'; | ||
import { Z } from 'zod-class'; | ||
|
||
export class CommunityRegisteredRequestDto extends Z.class({ email: z.string().email() }) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { TEntitlement } from '@n8n_io/license-sdk'; | ||
import axios, { AxiosError } from 'axios'; | ||
import { mock } from 'jest-mock-extended'; | ||
|
||
import type { WorkflowRepository } from '@/databases/repositories/workflow.repository'; | ||
|
@@ -7,6 +8,8 @@ import type { EventService } from '@/events/event.service'; | |
import type { License } from '@/license'; | ||
import { LicenseErrors, LicenseService } from '@/license/license.service'; | ||
|
||
jest.mock('axios'); | ||
|
||
describe('LicenseService', () => { | ||
const license = mock<License>(); | ||
const workflowRepository = mock<WorkflowRepository>(); | ||
|
@@ -84,4 +87,37 @@ describe('LicenseService', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('registerCommunityEdition', () => { | ||
test('on success', async () => { | ||
jest | ||
.spyOn(axios, 'post') | ||
.mockResolvedValueOnce({ data: { title: 'Title', text: 'Text', licenseKey: 'abc-123' } }); | ||
const data = await licenseService.registerCommunityEdition({ | ||
email: '[email protected]', | ||
instanceId: '123', | ||
instanceUrl: 'http://localhost', | ||
licenseType: 'community-registered', | ||
}); | ||
|
||
expect(data).toEqual({ title: 'Title', text: 'Text' }); | ||
expect(eventService.emit).toHaveBeenCalledWith('license-community-plus-registered', { | ||
email: '[email protected]', | ||
licenseKey: 'abc-123', | ||
}); | ||
}); | ||
|
||
test('on failure', async () => { | ||
jest.spyOn(axios, 'post').mockRejectedValueOnce(new AxiosError('Failed')); | ||
await expect( | ||
licenseService.registerCommunityEdition({ | ||
email: '[email protected]', | ||
instanceId: '123', | ||
instanceUrl: 'http://localhost', | ||
licenseType: 'community-registered', | ||
}), | ||
).rejects.toThrowError('Failed'); | ||
expect(eventService.emit).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.