-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from HF6-PROJECT/ara-31
feat: Added Item endpoints
- Loading branch information
Showing
8 changed files
with
374 additions
and
13 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 |
---|---|---|
|
@@ -137,6 +137,7 @@ describe('GET /api/item/:parentId', () => { | |
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
isStarred: false, | ||
linkedItemId: blob.id, | ||
}, | ||
]); | ||
}); | ||
|
@@ -228,3 +229,208 @@ describe('GET /api/item/:parentId', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/item/:id/single', () => { | ||
let userService: UserService; | ||
let folderService: FolderService; | ||
let authService: AuthService; | ||
let blobService: BlobService; | ||
let docsService: DocsService; | ||
|
||
let user: User; | ||
let otherUser: User; | ||
|
||
beforeAll(async () => { | ||
userService = UserServiceFactory.make(); | ||
folderService = FolderServiceFactory.make(); | ||
authService = AuthServiceFactory.make(); | ||
blobService = BlobServiceFactory.make(); | ||
docsService = DocsServiceFactory.make(); | ||
|
||
user = await userService.createUser({ | ||
name: 'Joe Biden the 4th', | ||
email: '[email protected]', | ||
password: '1234', | ||
}); | ||
otherUser = await userService.createUser({ | ||
name: 'Joe Biden the 3rd', | ||
email: '[email protected]', | ||
password: '4321', | ||
}); | ||
}); | ||
|
||
it('Should return status 200 and folder item from id', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const folder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
const responseFolder = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + folder.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(responseFolder.statusCode).toBe(200); | ||
expect(responseFolder.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'Folder1', | ||
color: '#123456', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.folder', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
isStarred: false, | ||
}); | ||
}); | ||
|
||
it('Should return status 200 and blob item from id', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const blob = await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: null, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
|
||
const responseBlob = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + blob.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(responseBlob.statusCode).toBe(200); | ||
expect(responseBlob.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'test1.txt', | ||
blobUrl: 'https://example.com/test1.txt', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'text/plain', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
isStarred: false, | ||
}); | ||
}); | ||
|
||
it('Should return status 200 and docs item from id', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const docs = await docsService.createDocs({ | ||
name: 'Docser', | ||
ownerId: user.id, | ||
parentId: null, | ||
text: 'Docs text here!', | ||
}); | ||
|
||
const responseDocs = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + docs.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(responseDocs.statusCode).toBe(200); | ||
expect(responseDocs.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'Docser', | ||
text: 'Docs text here!', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.docs', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
isStarred: false, | ||
}); | ||
}); | ||
|
||
it('Should return status 400, when item not found', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/1234/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(400); | ||
expect(response.json()).toEqual({ | ||
error: 'BadRequestError', | ||
errors: { | ||
_: ['Item not found'], | ||
}, | ||
statusCode: 400, | ||
}); | ||
}); | ||
|
||
it('Should return status 401, when unauthorized', async () => { | ||
const folder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: user.id, | ||
parentId: null, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + folder.id + '/single', | ||
headers: { | ||
authorization: 'WrongAuth!', | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
|
||
it('Should return status 401, when no access to file', async () => { | ||
const { accessToken } = await authService.createTokens(user.id); | ||
|
||
const folder = await folderService.createFolder({ | ||
name: 'Folder1', | ||
color: '#123456', | ||
ownerId: otherUser.id, | ||
parentId: null, | ||
}); | ||
|
||
const response = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + folder.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(response.statusCode).toBe(401); | ||
expect(response.json()).toEqual({ | ||
error: 'UnauthorizedError', | ||
errors: { | ||
_: ['Unauthorized'], | ||
}, | ||
statusCode: 401, | ||
}); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.