Add Activepieces integration for workflow automation
- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,235 @@
|
||||
|
||||
import {
|
||||
PlatformRole,
|
||||
PrincipalType,
|
||||
UserStatus,
|
||||
} from '@activepieces/shared'
|
||||
import { FastifyInstance } from 'fastify'
|
||||
import { StatusCodes } from 'http-status-codes'
|
||||
import { initializeDatabase } from '../../../../src/app/database'
|
||||
import { databaseConnection } from '../../../../src/app/database/database-connection'
|
||||
import { setupServer } from '../../../../src/app/server'
|
||||
import { generateMockToken } from '../../../helpers/auth'
|
||||
import {
|
||||
mockAndSaveBasicSetup,
|
||||
mockAndSaveBasicSetupWithApiKey,
|
||||
mockBasicUser,
|
||||
} from '../../../helpers/mocks'
|
||||
|
||||
let app: FastifyInstance | null = null
|
||||
|
||||
beforeAll(async () => {
|
||||
await initializeDatabase({ runMigrations: false })
|
||||
app = await setupServer()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await databaseConnection().destroy()
|
||||
await app?.close()
|
||||
})
|
||||
|
||||
describe('Enterprise User API', () => {
|
||||
describe('List users endpoint', () => {
|
||||
|
||||
it('Allows service accounts', async () => {
|
||||
// arrange
|
||||
const { mockOwner, mockPlatform, mockApiKey } = await mockAndSaveBasicSetupWithApiKey()
|
||||
|
||||
// act
|
||||
const response = await app?.inject({
|
||||
method: 'GET',
|
||||
url: '/v1/users',
|
||||
query: {
|
||||
platformId: mockPlatform.id,
|
||||
},
|
||||
headers: {
|
||||
authorization: `Bearer ${mockApiKey.value}`,
|
||||
},
|
||||
})
|
||||
|
||||
// assert
|
||||
expect(response?.statusCode).toBe(StatusCodes.OK)
|
||||
const responseBody = response?.json()
|
||||
|
||||
expect(Object.keys(responseBody)).toHaveLength(3)
|
||||
expect(responseBody.data).toHaveLength(1)
|
||||
expect(responseBody.data[0].id).toBe(mockOwner.id)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('Update user endpoint', () => {
|
||||
|
||||
it('Failed if own other platform', async () => {
|
||||
// arrange
|
||||
const { mockPlatform, mockProject } = await mockAndSaveBasicSetup()
|
||||
const { mockOwner: mockOwner2, mockPlatform: mockPlatform2 } = await mockAndSaveBasicSetup()
|
||||
const { mockUser } = await mockBasicUser({
|
||||
user: {
|
||||
platformId: mockPlatform.id,
|
||||
platformRole: PlatformRole.MEMBER,
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
const mockUserToken = await generateMockToken({
|
||||
id: mockOwner2.id,
|
||||
type: PrincipalType.USER,
|
||||
projectId: mockProject.id,
|
||||
platform: {
|
||||
id: mockPlatform2.id,
|
||||
},
|
||||
})
|
||||
|
||||
const response = await app?.inject({
|
||||
method: 'POST',
|
||||
url: `/v1/users/${mockUser.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${mockUserToken}`,
|
||||
},
|
||||
body: {
|
||||
status: UserStatus.INACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
// assert
|
||||
expect(response?.statusCode).toBe(StatusCodes.NOT_FOUND)
|
||||
})
|
||||
|
||||
it('Fail if not admin', async () => {
|
||||
// arrange
|
||||
const { mockPlatform, mockProject } = await mockAndSaveBasicSetup()
|
||||
const { mockUser } = await mockBasicUser({
|
||||
user: {
|
||||
platformId: mockPlatform.id,
|
||||
platformRole: PlatformRole.MEMBER,
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
const mockUserToken = await generateMockToken({
|
||||
id: mockUser.id,
|
||||
type: PrincipalType.USER,
|
||||
projectId: mockProject.id,
|
||||
platform: {
|
||||
id: mockPlatform.id,
|
||||
},
|
||||
})
|
||||
// act
|
||||
const response = await app?.inject({
|
||||
method: 'POST',
|
||||
url: `/v1/users/${mockUser.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${mockUserToken}`,
|
||||
},
|
||||
body: {
|
||||
status: UserStatus.INACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
expect(response?.statusCode).toBe(StatusCodes.FORBIDDEN)
|
||||
})
|
||||
|
||||
it('Allows service accounts to activate', async () => {
|
||||
// arrange
|
||||
const { mockPlatform, mockApiKey } = await mockAndSaveBasicSetupWithApiKey()
|
||||
const { mockUser } = await mockBasicUser({
|
||||
user: {
|
||||
platformId: mockPlatform.id,
|
||||
platformRole: PlatformRole.MEMBER,
|
||||
status: UserStatus.INACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
// act
|
||||
const response = await app?.inject({
|
||||
method: 'POST',
|
||||
url: `/v1/users/${mockUser.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${mockApiKey.value}`,
|
||||
},
|
||||
body: {
|
||||
status: UserStatus.ACTIVE,
|
||||
},
|
||||
})
|
||||
|
||||
// assert
|
||||
expect(response?.statusCode).toBe(StatusCodes.OK)
|
||||
|
||||
const responseJson = response?.json()
|
||||
expect(responseJson.id).toBe(mockUser.id)
|
||||
expect(responseJson.password).toBeUndefined()
|
||||
expect(responseJson.status).toBe(UserStatus.ACTIVE)
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
describe('Delete user endpoint', () => {
|
||||
|
||||
it('Fails if user is not platform owner', async () => {
|
||||
// arrange
|
||||
const { mockPlatform, mockProject } = await mockAndSaveBasicSetupWithApiKey()
|
||||
const { mockUser } = await mockBasicUser({
|
||||
user: {
|
||||
platformId: mockPlatform.id,
|
||||
platformRole: PlatformRole.MEMBER,
|
||||
},
|
||||
})
|
||||
|
||||
const mockUserToken = await generateMockToken({
|
||||
id: mockUser.id,
|
||||
type: PrincipalType.USER,
|
||||
projectId: mockProject.id,
|
||||
platform: {
|
||||
id: mockPlatform.id,
|
||||
},
|
||||
})
|
||||
|
||||
// act
|
||||
const response = await app?.inject({
|
||||
method: 'DELETE',
|
||||
url: `/v1/users/${mockUser.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${mockUserToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
// assert
|
||||
expect(response?.statusCode).toBe(StatusCodes.FORBIDDEN)
|
||||
})
|
||||
|
||||
it('Allows platform owner to delete user', async () => {
|
||||
// arrange
|
||||
const { mockOwner, mockPlatform, mockProject } = await mockAndSaveBasicSetupWithApiKey()
|
||||
const { mockUser } = await mockBasicUser({
|
||||
user: {
|
||||
platformId: mockPlatform.id,
|
||||
platformRole: PlatformRole.MEMBER,
|
||||
},
|
||||
})
|
||||
|
||||
const mockOwnerToken = await generateMockToken({
|
||||
id: mockOwner.id,
|
||||
type: PrincipalType.USER,
|
||||
projectId: mockProject.id,
|
||||
platform: {
|
||||
id: mockPlatform.id,
|
||||
},
|
||||
})
|
||||
|
||||
// act
|
||||
const response = await app?.inject({
|
||||
method: 'DELETE',
|
||||
url: `/v1/users/${mockUser.id}`,
|
||||
headers: {
|
||||
authorization: `Bearer ${mockOwnerToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
// assert
|
||||
expect(response?.statusCode).toBe(StatusCodes.NO_CONTENT)
|
||||
})
|
||||
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user