Skip to content

Commit

Permalink
Merge branch 'add--project-frontend-api-with-test-and-fix-backend-pro…
Browse files Browse the repository at this point in the history
…ject' of https://github.com/Sma1lboy/GeneratorAI into add--project-frontend-api-with-test-and-fix-backend-project
  • Loading branch information
ZHallen122 committed Oct 25, 2024
2 parents 273ff2b + 6b8c307 commit cb906ef
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 84 deletions.
7 changes: 3 additions & 4 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

preset: 'ts-jest',
testEnvironment: 'node',
};
5 changes: 4 additions & 1 deletion frontend/src/app/api/project/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export const REMOVE_PACKAGE_FROM_PROJECT = gql`
}
`;

export const removePackageFromProject = async (projectId: string, packageId: string): Promise<boolean> => {
export const removePackageFromProject = async (
projectId: string,
packageId: string
): Promise<boolean> => {
try {
const response = await client.mutate({
mutation: REMOVE_PACKAGE_FROM_PROJECT,
Expand Down
79 changes: 42 additions & 37 deletions frontend/src/test/projectApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
import { getUserProjects, getProjectDetails, deleteProject, upsertProject, removePackageFromProject } from '../app/api/project/route';
import {
getUserProjects,
getProjectDetails,
deleteProject,
upsertProject,
removePackageFromProject,
} from '../app/api/project/route';

describe('Project API', () => {
let projectId: string;
let packageId: string;

it('should upsert a project', async () => {
const upsertProjectInput = {
projectName: 'Test Project',
projectPackages: ['Package 1', 'Package 2'],
};
const project = await upsertProject(upsertProjectInput);
expect(project).toHaveProperty('id');
projectId = project.id;
console.log('Project id is: ' + projectId)
packageId = project.projectPackages[0].id;
});

it('should get user projects', async () => {
const projects = await getUserProjects();
expect(Array.isArray(projects)).toBe(true);
expect(projects.length).toBeGreaterThan(0);
});

it('should get project details', async () => {
const projectDetails = await getProjectDetails(projectId);
expect(projectDetails).toHaveProperty('id', projectId);
});

it('should remove a package from project', async () => {
const removed = await removePackageFromProject(projectId, packageId);
expect(removed).toBe(true);
});

it('should delete a project', async () => {
const deleted = await deleteProject(projectId);
expect(deleted).toBe(true);
});
let projectId: string;
let packageId: string;

it('should upsert a project', async () => {
const upsertProjectInput = {
projectName: 'Test Project',
projectPackages: ['Package 1', 'Package 2'],
};
const project = await upsertProject(upsertProjectInput);
expect(project).toHaveProperty('id');
projectId = project.id;
console.log('Project id is: ' + projectId);
packageId = project.projectPackages[0].id;
});

it('should get user projects', async () => {
const projects = await getUserProjects();
expect(Array.isArray(projects)).toBe(true);
expect(projects.length).toBeGreaterThan(0);
});

it('should get project details', async () => {
const projectDetails = await getProjectDetails(projectId);
expect(projectDetails).toHaveProperty('id', projectId);
});

it('should remove a package from project', async () => {
const removed = await removePackageFromProject(projectId, packageId);
expect(removed).toBe(true);
});

it('should delete a project', async () => {
const deleted = await deleteProject(projectId);
expect(deleted).toBe(true);
});
});
13 changes: 8 additions & 5 deletions frontend/src/utils/apolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { ApolloClient, InMemoryCache, HttpLink, ApolloLink, concat } from '@apollo/client';
import {
ApolloClient,
InMemoryCache,
HttpLink,
ApolloLink,
concat,
} from '@apollo/client';

const httpLink = new HttpLink({
// uri: process.env.NEXT_PUBLIC_API_BASE_URL,
// uri: process.env.NEXT_PUBLIC_API_BASE_URL,
uri: 'http://localhost:8080/graphql',
});

Expand All @@ -25,6 +31,3 @@ const client = new ApolloClient({
});

export default client;



Loading

0 comments on commit cb906ef

Please sign in to comment.