-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/wrong_project_name' into staging
- Loading branch information
Showing
12 changed files
with
1,233 additions
and
0 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
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,93 @@ | ||
import { beforeEach, describe, vi } from 'vitest'; | ||
import profileApi from '../profile'; | ||
import http from '@/services/api/http'; | ||
import { getProject, getToken } from '@/utils/config'; | ||
|
||
vi.mock('@/services/api/http'); | ||
vi.mock('@/utils/config'); | ||
|
||
describe('Profile services', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('me', () => { | ||
it('should call the correct endpoint and return user data', async () => { | ||
const mockResponse = { data: { name: 'Test User' } }; | ||
http.get.mockResolvedValue(mockResponse); | ||
getProject.mockReturnValue('project-uuid'); | ||
|
||
const result = await profileApi.me(); | ||
|
||
expect(http.get).toHaveBeenCalledWith('/accounts/profile/', { | ||
params: { project_uuid: 'project-uuid' }, | ||
}); | ||
expect(result).toEqual(mockResponse.data); | ||
}); | ||
}); | ||
|
||
describe('onboarded', () => { | ||
it('should verify user onboarding status', async () => { | ||
const mockResponse = { data: { first_access: false } }; | ||
http.get.mockResolvedValue(mockResponse); | ||
getProject.mockReturnValue('project-uuid'); | ||
|
||
const result = await profileApi.onboarded(); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'/permission/project/verify_access/', | ||
{ params: { project: 'project-uuid' } }, | ||
); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('onboard', () => { | ||
it('should call the correct endpoint to onboard user', async () => { | ||
getProject.mockReturnValue('project-uuid'); | ||
http.patch.mockResolvedValue(); | ||
|
||
await profileApi.onboard(); | ||
|
||
expect(http.patch).toHaveBeenCalledWith( | ||
'/permission/project/update_access/?project=project-uuid', | ||
); | ||
}); | ||
}); | ||
|
||
describe('status', () => { | ||
it('should fetch the project connection status', async () => { | ||
const mockResponse = { data: { connection_status: 'online' } }; | ||
http.get.mockResolvedValue(mockResponse); | ||
getProject.mockReturnValue('project-uuid'); | ||
getToken.mockReturnValue('fake-token'); | ||
|
||
const result = await profileApi.status(); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
'/internal/permission/project/status/?project=project-uuid', | ||
{ | ||
headers: { Authorization: 'Bearer fake-token' }, | ||
}, | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
}); | ||
|
||
describe('updateStatus', () => { | ||
it('should update the project connection status', async () => { | ||
const payload = { projectUuid: 'project-uuid', status: 'offline' }; | ||
http.post.mockResolvedValue(); | ||
|
||
await profileApi.updateStatus(payload); | ||
|
||
expect(http.post).toHaveBeenCalledWith( | ||
'/internal/permission/project/status/', | ||
{ | ||
project: 'project-uuid', | ||
status: 'offline', | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
150 changes: 150 additions & 0 deletions
150
src/services/api/resources/chats/__tests__/discussion.unit.spec.js
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,150 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import discussionService from '../discussion'; | ||
import http from '@/services/api/http'; | ||
import { useRooms } from '@/store/modules/chats/rooms'; | ||
import { getProject } from '@/utils/config'; | ||
|
||
vi.mock('@/services/api/http'); | ||
vi.mock('@/store/modules/chats/rooms'); | ||
vi.mock('@/utils/config'); | ||
|
||
const mockRoom = { uuid: 'mock-room-uuid' }; | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
useRooms.mockReturnValue({ activeRoom: mockRoom }); | ||
getProject.mockReturnValue('mock-project-uuid'); | ||
}); | ||
|
||
describe('discussionService', () => { | ||
it('should create a discussion', async () => { | ||
const mockResponse = { id: 'mock-discussion-id' }; | ||
http.post.mockResolvedValue({ data: mockResponse }); | ||
|
||
const payload = { | ||
queue: 'mock-queue', | ||
subject: 'mock-subject', | ||
initial_message: 'mock-message', | ||
}; | ||
|
||
const result = await discussionService.create(payload); | ||
|
||
expect(http.post).toHaveBeenCalledWith('discussion/', { | ||
room: 'mock-room-uuid', | ||
queue: 'mock-queue', | ||
subject: 'mock-subject', | ||
initial_message: 'mock-message', | ||
}); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should delete a discussion', async () => { | ||
const mockDiscussionUuid = 'mock-discussion-uuid'; | ||
|
||
http.delete.mockResolvedValue({ status: 200 }); | ||
|
||
await discussionService.delete({ | ||
discussionUuid: mockDiscussionUuid, | ||
}); | ||
|
||
expect(http.delete).toHaveBeenCalledWith( | ||
`discussion/${mockDiscussionUuid}/`, | ||
); | ||
}); | ||
|
||
it('should add an agent to a discussion', async () => { | ||
const mockDiscussionUuid = 'mock-discussion-uuid'; | ||
const mockEmail = '[email protected]'; | ||
const mockResponse = { success: true }; | ||
http.post.mockResolvedValue({ data: mockResponse }); | ||
|
||
const result = await discussionService.addAgent({ | ||
discussionUuid: mockDiscussionUuid, | ||
user_email: mockEmail, | ||
}); | ||
|
||
expect(http.post).toHaveBeenCalledWith( | ||
`discussion/${mockDiscussionUuid}/add_agents/`, | ||
{ user_email: mockEmail }, | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should get discussion details', async () => { | ||
const mockDiscussionUuid = 'mock-discussion-uuid'; | ||
const mockResponse = { id: mockDiscussionUuid }; | ||
http.get.mockResolvedValue({ data: mockResponse }); | ||
|
||
const result = await discussionService.getDiscussionDetails({ | ||
discussionUuid: mockDiscussionUuid, | ||
}); | ||
|
||
expect(http.get).toHaveBeenCalledWith(`discussion/${mockDiscussionUuid}/`); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should get discussion agents', async () => { | ||
const mockDiscussionUuid = 'mock-discussion-uuid'; | ||
const mockResponse = { agents: [] }; | ||
http.get.mockResolvedValue({ data: mockResponse }); | ||
|
||
const result = await discussionService.getDiscussionAgents({ | ||
discussionUuid: mockDiscussionUuid, | ||
}); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
`discussion/${mockDiscussionUuid}/list_agents/`, | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should get sectors', async () => { | ||
const mockResponse = { sectors: [] }; | ||
http.get.mockResolvedValue({ data: mockResponse }); | ||
|
||
const result = await discussionService.getSectors(); | ||
|
||
expect(http.get).toHaveBeenCalledWith( | ||
`project/mock-project-uuid/list_discussion_sector/`, | ||
{ limit: 9999 }, | ||
); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should list all discussions', async () => { | ||
const mockResponse = { discussions: [] }; | ||
http.get.mockResolvedValue({ data: mockResponse }); | ||
|
||
const filters = { status: 'active' }; | ||
const viewedAgent = '[email protected]'; | ||
|
||
const result = await discussionService.listAll({ viewedAgent, filters }); | ||
|
||
expect(http.get).toHaveBeenCalledWith('discussion/', { | ||
params: { | ||
project: 'mock-project-uuid', | ||
is_active: true, | ||
limit: 9999, | ||
status: 'active', | ||
email: '[email protected]', | ||
}, | ||
}); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
|
||
it('should list closed discussions', async () => { | ||
const mockRoomId = 'mock-room-id'; | ||
const mockResponse = { discussions: [] }; | ||
http.get.mockResolvedValue({ data: mockResponse }); | ||
|
||
const result = await discussionService.listCloseds({ roomId: mockRoomId }); | ||
|
||
expect(http.get).toHaveBeenCalledWith('discussion/', { | ||
params: { | ||
project: 'mock-project-uuid', | ||
room: mockRoomId, | ||
}, | ||
}); | ||
expect(result).toEqual(mockResponse); | ||
}); | ||
}); |
Oops, something went wrong.