Skip to content

Commit

Permalink
Merge branch 'fix/wrong_project_name' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuseduardomedeiros committed Dec 11, 2024
2 parents e261377 + 3bfbd43 commit 5f38b01
Show file tree
Hide file tree
Showing 12 changed files with 1,233 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ import { useDashboard } from './store/modules/dashboard';
import initHotjar from '@/plugins/Hotjar';
import { getProject } from '@/utils/config';
import { setProject as setProjectLocalStorage } from '@/utils/config';
import moment from 'moment';
export default {
name: 'App',
setup() {
const projectUuid = window.location.href.split('projectUuid=')[1];
if (projectUuid) setProjectLocalStorage(projectUuid);
},
data() {
return {
ws: null,
Expand Down
93 changes: 93 additions & 0 deletions src/services/api/resources/__tests__/profile.unit.spec.js
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 src/services/api/resources/chats/__tests__/discussion.unit.spec.js
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);
});
});
Loading

0 comments on commit 5f38b01

Please sign in to comment.