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

chore: fix project members view #292

Merged
merged 5 commits into from
Jan 15, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react-string-replace": "^1.1.1",
"react-syntax-highlighter": "^15.5.0",
"react-tailwindcss-datepicker": "^1.6.6",
"sharp": "^0.33.1",
"sharp": "^0.33.2",
"swr": "^2.2.4",
"validator": "^13.11.0",
"zustand": "^4.4.7"
Expand All @@ -42,7 +42,7 @@
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^14.1.2",
"@types/react": "18.2.47",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"@types/react-syntax-highlighter": "^15.5.11",
"@types/validator": "^13.11.8",
Expand Down
12 changes: 6 additions & 6 deletions frontend/public/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
},
"members": {
"admin": "Admin",
"cancel": "Cancel",
"continue": "Continue",
"edit": "Edit",
"emailAddress": "Email Address",
"emailAddresses": "Email address(es)",
"emailPlaceholder": "[email protected]",
Expand All @@ -233,16 +236,13 @@
"member": "Member",
"members": "Members",
"name": "Name",
"ok": "Ok",
"removeMember": "Remove Member",
"remove": "Remove",
"removeUserWarningMessage": "Are you sure you want to remove {username} from the {projectName} project?",
"role": "Role",
"roleUpdated": "Role Updated",
"roles": "Roles",
"sendInvite": "Send Invite",
"userRemoved": "User Removed",
"usersInvited": "User(s) Invited",
"warning": "Warning",
"warningMessage": "Your about to remove a user access from this project"
"usersInvited": "User(s) Invited"
},
"navbar": {
"createNewProject": "Create New Project",
Expand Down
74 changes: 74 additions & 0 deletions frontend/src/api/project-invitation-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { ProjectFactory, ProjectInvitationFactory } from 'tests/factories';
import { mockFetch } from 'tests/mocks';

import {
handleDeleteProjectInvitation,
handleRetrieveProjectInvitations,
} from '@/api/project-invitation-api';
import { HttpMethod } from '@/constants';

describe('project invitations API tests', () => {
const bearerToken = 'Bearer test_token';

describe('handleRetrieveProjectInvitations', () => {
it('returns a list of project users', async () => {
const project = await ProjectFactory.build();
const projectInvitations = await ProjectInvitationFactory.batch(2);

mockFetch.mockResolvedValueOnce({
json: () => Promise.resolve(projectInvitations),
ok: true,
});

const data = await handleRetrieveProjectInvitations({
projectId: project.id,
});

expect(data).toEqual(projectInvitations);
expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/invitation/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Get,
},
);
});
});

describe('handleDeleteProjectInvitation', () => {
it('returns a list of project users', async () => {
const project = await ProjectFactory.build();
const projectInvitation = await ProjectInvitationFactory.build();

mockFetch.mockResolvedValueOnce({
json: () => Promise.resolve(),
ok: true,
});

await handleDeleteProjectInvitation({
invitationId: projectInvitation.id,
projectId: project.id,
});

expect(mockFetch).toHaveBeenCalledWith(
new URL(
`http://www.example.com/v1/projects/${project.id}/invitation/${projectInvitation.id}/`,
),
{
headers: {
'Authorization': bearerToken,
'Content-Type': 'application/json',
'X-Request-Id': expect.any(String),
},
method: HttpMethod.Delete,
},
);
});
});
});
27 changes: 27 additions & 0 deletions frontend/src/api/project-invitation-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { fetcher } from '@/api/fetcher';
import { HttpMethod } from '@/constants';
import { ProjectInvitation } from '@/types';

export async function handleRetrieveProjectInvitations({
projectId,
}: {
projectId: string;
}): Promise<ProjectInvitation[]> {
return await fetcher<ProjectInvitation[]>({
method: HttpMethod.Get,
url: `projects/${projectId}/invitation/`,
});
}

export async function handleDeleteProjectInvitation({
projectId,
invitationId,
}: {
invitationId: string;
projectId: string;
}): Promise<void> {
await fetcher<undefined>({
method: HttpMethod.Delete,
url: `projects/${projectId}/invitation/${invitationId}/`,
});
}
4 changes: 2 additions & 2 deletions frontend/src/api/project-users-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
handleAddUsersToProject,
handleRemoveUserFromProject,
handleRetrieveProjectUsers,
handleUpdateUserToPermission,
handleUpdateUserPermission,
} from '@/api/index';
import { HttpMethod } from '@/constants';
import { AddUserToProjectBody } from '@/types';
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('project users API tests', () => {
userId: userAccount.id,
};

const data = await handleUpdateUserToPermission({
const data = await handleUpdateUserPermission({
data: body,
projectId: project.id,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/project-users-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function handleAddUsersToProject({
});
}

export async function handleUpdateUserToPermission({
export async function handleUpdateUserPermission({
projectId,
data,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,38 @@ describe('PromptConfigCreateWizard Page tests', () => {
});

it('does not allow the user to save the config if messages are empty', async () => {
const promptConfig = OpenAIPromptConfigFactory.buildSync();
mockFetch.mockResolvedValue({
json: () => Promise.resolve(promptConfig),
ok: true,
});

const store = getStore();
act(() => {
store.setConfigName(faker.lorem.word());
store.setMessages([]);
store.setParameters(promptConfig.modelParameters);
store.setModelType(promptConfig.modelType);
store.setModelVendor(promptConfig.modelVendor);
store.setNextWizardStage();
store.setNextWizardStage();
});

render(
<PromptConfigCreateWizard params={{ applicationId, projectId }} />,
);

const continueButton = screen.getByTestId(
'config-create-wizard-continue-button',
);
expect(continueButton).toBeInTheDocument();
fireEvent.click(continueButton);

await waitFor(() => {
expect(
screen.getByTestId('parameters-and-prompt-form-container'),
screen.getByTestId('prompt-config-testing-form'),
).toBeInTheDocument();
});

expect(continueButton).toBeInTheDocument();
expect(continueButton).toBeDisabled();
const saveButton = screen.getByTestId(
'config-create-wizard-save-button',
);
expect(saveButton).toBeInTheDocument();
expect(saveButton).toBeDisabled();
});

it('allows the user to continue to the third stage if messages are not empty', async () => {
Expand Down Expand Up @@ -260,6 +269,7 @@ describe('PromptConfigCreateWizard Page tests', () => {
store.setNextWizardStage();
store.setNextWizardStage();
});

render(
<PromptConfigCreateWizard params={{ applicationId, projectId }} />,
);
Expand Down
Loading
Loading