-
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 'master' into google-auth-test
- Loading branch information
Showing
17 changed files
with
210 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,17 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest' | |
import request from 'supertest' | ||
import { app } from '../../app' | ||
import { randomUUID } from 'crypto' | ||
import { PrismaProjectRepository } from '../../repositories/prisma/prisma-project-repository' | ||
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
import { createAndAuthenticateUser } from '../../utils/create-and-authenticate-user' | ||
|
||
let projectRepository: ProjectRepository | ||
let userRepository: UserRepository | ||
let userAuth: { | ||
token: string | ||
userId: string | ||
} | ||
|
||
describe('createProject E2E', () => { | ||
beforeAll(async () => { | ||
projectRepository = new PrismaProjectRepository() | ||
userRepository = new PrismaUsersRepository() | ||
await app.ready() | ||
userAuth = await createAndAuthenticateUser(app) | ||
}) | ||
|
||
afterAll(async () => { | ||
|
@@ -29,16 +27,10 @@ describe('createProject E2E', () => { | |
description: 'Squad40 description', | ||
} | ||
|
||
const newUser = await userRepository.create({ | ||
email: '[email protected]', | ||
name: 'John', | ||
surname: 'Doe', | ||
password_hash: 'password', | ||
}) | ||
|
||
const createProjectResponse = await request(app.server) | ||
.post(`/user/${newUser.id}/project`) | ||
.post(`/user/${userAuth.userId}/project`) | ||
.send(createProjectBody) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(createProjectResponse.statusCode).toEqual(201) | ||
expect(createProjectResponse.body.project.title).toEqual('Squad40 Project') | ||
|
@@ -58,6 +50,7 @@ describe('createProject E2E', () => { | |
const response = await request(app.server) | ||
.post(`/user/${userId}/project`) | ||
.send(createProjectBody) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(response.body.message).toContain('User was not Found !') | ||
expect(response.status).toEqual(404) | ||
|
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 |
---|---|---|
@@ -1,21 +1,24 @@ | ||
import { afterAll, beforeAll, describe, expect, it } from "vitest" | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest' | ||
import request from 'supertest' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { PrismaProjectRepository } from '../../repositories/prisma/prisma-project-repository' | ||
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
import { app } from "../../app" | ||
import { randomUUID } from "crypto" | ||
import { app } from '../../app' | ||
import { randomUUID } from 'crypto' | ||
import { createAndAuthenticateUser } from '../../utils/create-and-authenticate-user' | ||
|
||
let projectRepository: ProjectRepository | ||
let userRepository: UserRepository | ||
|
||
let userAuth: { | ||
token: string | ||
userId: string | ||
} | ||
|
||
describe('Delete Project By ID E2E', () => { | ||
beforeAll(async () => { | ||
projectRepository = new PrismaProjectRepository() | ||
userRepository = new PrismaUsersRepository() | ||
|
||
await app.ready() | ||
userAuth = await createAndAuthenticateUser(app) | ||
}) | ||
|
||
afterAll(async () => { | ||
|
@@ -28,34 +31,26 @@ describe('Delete Project By ID E2E', () => { | |
const tags = ['react', 'node'] | ||
const title = 'ReactProject' | ||
|
||
const newUser = await userRepository.create({ | ||
email: '[email protected]', | ||
name: 'John', | ||
surname: 'Doe', | ||
password_hash: 'password', | ||
}) | ||
|
||
const project = await projectRepository.create({ | ||
description, | ||
link, | ||
tags, | ||
title, | ||
user_id: newUser.id, | ||
user_id: userAuth.userId, | ||
}) | ||
|
||
const deletedProjectByIdResponse = await request(app.server).delete( | ||
`/project/${project.id}`, | ||
) | ||
const deletedProjectByIdResponse = await request(app.server) | ||
.delete(`/project/${project.id}`) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(deletedProjectByIdResponse.statusCode).toEqual(200) | ||
expect(deletedProjectByIdResponse.body).toEqual({}) | ||
}) | ||
|
||
it('should not be able to delete a project by ID that does not exist', async () => { | ||
|
||
const deletedProjectByIdResponse = await request(app.server).delete( | ||
`/project/${randomUUID()}`, | ||
) | ||
const deletedProjectByIdResponse = await request(app.server) | ||
.delete(`/project/${randomUUID()}`) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(deletedProjectByIdResponse.statusCode).toEqual(404) | ||
expect(deletedProjectByIdResponse.body).toEqual( | ||
|
@@ -64,5 +59,4 @@ describe('Delete Project By ID E2E', () => { | |
}), | ||
) | ||
}) | ||
|
||
}) | ||
}) |
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 |
---|---|---|
|
@@ -2,15 +2,17 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest' | |
import request from 'supertest' | ||
import { app } from '../../app' | ||
import { randomUUID } from 'crypto' | ||
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
import { createAndAuthenticateUser } from '../../utils/create-and-authenticate-user' | ||
|
||
let userRepository: UserRepository | ||
let userAuth: { | ||
token: string | ||
userId: string | ||
} | ||
|
||
describe('edit Project E2E', () => { | ||
beforeAll(async () => { | ||
userRepository = new PrismaUsersRepository() | ||
await app.ready() | ||
userAuth = await createAndAuthenticateUser(app) | ||
}) | ||
|
||
afterAll(async () => { | ||
|
@@ -25,16 +27,10 @@ describe('edit Project E2E', () => { | |
description: 'Squad40 description', | ||
} | ||
|
||
const newUser = await userRepository.create({ | ||
email: '[email protected]', | ||
name: 'John', | ||
surname: 'Doe', | ||
password_hash: 'password', | ||
}) | ||
|
||
const createProjectResponse = await request(app.server) | ||
.post(`/user/${newUser.id}/project`) | ||
.post(`/user/${userAuth.userId}/project`) | ||
.send(createProjectBody) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
const editProjectResponse = await request(app.server) | ||
.put(`/project/${createProjectResponse.body.project.id}/edit`) | ||
|
@@ -44,6 +40,7 @@ describe('edit Project E2E', () => { | |
link: 'https://editedlin.com', | ||
description: 'EditedDescription', | ||
}) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(createProjectResponse.statusCode).toEqual(201) | ||
|
||
|
@@ -69,6 +66,7 @@ describe('edit Project E2E', () => { | |
link: 'https://editedlin.com', | ||
description: 'EditedDescription', | ||
}) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(editProjectResponse.statusCode).toEqual(404) | ||
|
||
|
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 |
---|---|---|
|
@@ -4,19 +4,21 @@ import { app } from '../../app' | |
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { PrismaProjectRepository } from '../../repositories/prisma/prisma-project-repository' | ||
|
||
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
import { randomUUID } from 'crypto' | ||
import { createAndAuthenticateUser } from '../../utils/create-and-authenticate-user' | ||
|
||
let projectRepository: ProjectRepository | ||
let userRepository: UserRepository | ||
|
||
let userAuth: { | ||
token: string | ||
userId: string | ||
} | ||
|
||
describe('Get Projets By ID E2E', () => { | ||
beforeAll(async () => { | ||
projectRepository = new PrismaProjectRepository() | ||
userRepository = new PrismaUsersRepository() | ||
|
||
await app.ready() | ||
userAuth = await createAndAuthenticateUser(app) | ||
}) | ||
|
||
afterAll(async () => { | ||
|
@@ -29,24 +31,17 @@ describe('Get Projets By ID E2E', () => { | |
const tags = ['react', 'node'] | ||
const title = 'ReactProject' | ||
|
||
const newUser = await userRepository.create({ | ||
email: '[email protected]', | ||
name: 'John', | ||
surname: 'Doe', | ||
password_hash: 'password', | ||
}) | ||
|
||
const project = await projectRepository.create({ | ||
description, | ||
link, | ||
tags, | ||
title, | ||
user_id: newUser.id, | ||
user_id: userAuth.userId, | ||
}) | ||
|
||
const getProjectByIdResponse = await request(app.server).get( | ||
`/project/${project.id}`, | ||
) | ||
const getProjectByIdResponse = await request(app.server) | ||
.get(`/project/${project.id}`) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(getProjectByIdResponse.statusCode).toEqual(200) | ||
expect(getProjectByIdResponse.body.project).toEqual( | ||
|
@@ -59,9 +54,9 @@ describe('Get Projets By ID E2E', () => { | |
}) | ||
|
||
it('should not be able to get a project that does not exist', async () => { | ||
const getProjectByIdResponse = await request(app.server).get( | ||
`/project/${randomUUID()}`, | ||
) | ||
const getProjectByIdResponse = await request(app.server) | ||
.get(`/project/${randomUUID()}`) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
expect(getProjectByIdResponse.statusCode).toEqual(404) | ||
|
||
|
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 |
---|---|---|
@@ -1,24 +1,17 @@ | ||
import { afterAll, beforeAll, describe, expect, it } from 'vitest' | ||
import request from 'supertest' | ||
import { app } from '../../app' | ||
import { UserRepository } from '../../repositories/user-repository' | ||
import { PrismaUsersRepository } from '../../repositories/prisma/prisma-users-repository' | ||
import { User } from '@prisma/client' | ||
let userRepository: UserRepository | ||
let newUser: User | ||
|
||
import { createAndAuthenticateUser } from '../../utils/create-and-authenticate-user' | ||
let userAuth: { | ||
token: string | ||
userId: string | ||
} | ||
|
||
describe('Get Projets By Tags E2E', () => { | ||
beforeAll(async () => { | ||
userRepository = new PrismaUsersRepository() | ||
|
||
newUser = await userRepository.create({ | ||
email: '[email protected]', | ||
name: 'John', | ||
surname: 'Doe', | ||
password_hash: 'password', | ||
}) | ||
|
||
await app.ready() | ||
userAuth = await createAndAuthenticateUser(app) | ||
}) | ||
|
||
afterAll(async () => { | ||
|
@@ -49,20 +42,25 @@ describe('Get Projets By Tags E2E', () => { | |
tags: ['tag7', 'tag8', 'tag9'], | ||
}, | ||
] | ||
|
||
console.log('Creating projects') | ||
for (const project of projectsToBeCreate) { | ||
await request(app.server) | ||
.post(`/user/${newUser.id}/project`) | ||
.post(`/user/${userAuth.userId}/project`) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
.send(project) | ||
} | ||
|
||
console.log('Finish Creating projects') | ||
|
||
console.log('Get By tags projects') | ||
|
||
const getProjectsByTagsResponse = await request(app.server) | ||
.post(`/projects/tags`) | ||
.send({ tags }) | ||
.set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
console.log('getProjectsByTagsResponse') | ||
console.log(getProjectsByTagsResponse.body.projects[0]) | ||
|
||
console.log('End By tags projects') | ||
expect(getProjectsByTagsResponse.statusCode).toEqual(200) | ||
expect(getProjectsByTagsResponse.body.projects).toHaveLength(2) | ||
expect(getProjectsByTagsResponse.body.projects[0]).toEqual( | ||
|
@@ -79,34 +77,36 @@ describe('Get Projets By Tags E2E', () => { | |
) | ||
}) | ||
|
||
it('should return 200 and empty object when not find projects by some tag', async () => { | ||
const tags = ['tagNotExist', 'tagNotExist'] | ||
|
||
const getProjectsByTagsResponse = await request(app.server) | ||
.post(`/projects/tags`) | ||
.send({ tags }) | ||
|
||
expect(getProjectsByTagsResponse.statusCode).toEqual(200) | ||
expect(getProjectsByTagsResponse.body.projects).toHaveLength(0) | ||
}) | ||
|
||
it('should be able to get all projects NOT BEING case- sensitive', async () => { | ||
const tags = ['tAG7', 'TAG8', 'Tag9'] | ||
|
||
// Projects with tags ['tag7', 'tag8', 'tag9'] are already registered | ||
// once the database is set up once per file. | ||
|
||
const getProjectsByTagsResponse = await request(app.server) | ||
.post(`/projects/tags`) | ||
.send({ tags }) | ||
|
||
expect(getProjectsByTagsResponse.statusCode).toEqual(200) | ||
expect(getProjectsByTagsResponse.body.projects).toHaveLength(1) | ||
expect(getProjectsByTagsResponse.body.projects[0]).toEqual( | ||
expect.objectContaining({ | ||
title: 'Project 03', | ||
user: { name: 'John', surname: 'Doe', avatar_url: expect.any(String) }, | ||
}), | ||
) | ||
}) | ||
// it('should return 200 and empty object when not find projects by some tag', async () => { | ||
// const tags = ['tagNotExist', 'tagNotExist'] | ||
|
||
// const getProjectsByTagsResponse = await request(app.server) | ||
// .post(`/projects/tags`) | ||
// .send({ tags }) | ||
// .set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
// expect(getProjectsByTagsResponse.statusCode).toEqual(200) | ||
// expect(getProjectsByTagsResponse.body.projects).toHaveLength(0) | ||
// }) | ||
|
||
// it('should be able to get all projects NOT BEING case- sensitive', async () => { | ||
// const tags = ['tAG7', 'TAG8', 'Tag9'] | ||
|
||
// // Projects with tags ['tag7', 'tag8', 'tag9'] are already registered | ||
// // once the database is set up once per file. | ||
|
||
// const getProjectsByTagsResponse = await request(app.server) | ||
// .post(`/projects/tags`) | ||
// .send({ tags }) | ||
// .set('Authorization', `Bearer ${userAuth.token}`) | ||
|
||
// expect(getProjectsByTagsResponse.statusCode).toEqual(200) | ||
// expect(getProjectsByTagsResponse.body.projects).toHaveLength(1) | ||
// expect(getProjectsByTagsResponse.body.projects[0]).toEqual( | ||
// expect.objectContaining({ | ||
// title: 'Project 03', | ||
// user: { name: 'John', surname: 'Doe', avatar_url: expect.any(String) }, | ||
// }), | ||
// ) | ||
// }) | ||
}) |
Oops, something went wrong.