-
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.
- Loading branch information
1 parent
23b5c62
commit bf902cf
Showing
7 changed files
with
233 additions
and
76 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,212 @@ describe('GET /api/item/:parentId', () => { | |
}); | ||
}); | ||
}); | ||
|
||
describe('GET /api/item/:parentId/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 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 blob = await blobService.createBlob({ | ||
mimeType: 'text/plain', | ||
name: 'test1.txt', | ||
ownerId: user.id, | ||
parentId: null, | ||
blobUrl: 'https://example.com/test1.txt', | ||
}); | ||
|
||
const docs = await docsService.createDocs({ | ||
name: 'Docser', | ||
ownerId: user.id, | ||
parentId: null, | ||
text: 'Docs text here!', | ||
}); | ||
|
||
const responseFolder = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + folder.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
const responseBlob = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + blob.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
const responseDocs = await global.fastify.inject({ | ||
method: 'GET', | ||
url: '/api/item/' + docs.id + '/single', | ||
headers: { | ||
authorization: 'Bearer ' + accessToken, | ||
}, | ||
}); | ||
|
||
expect(responseFolder.statusCode).toBe(200); | ||
expect(responseFolder.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'Folder1', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.folder', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
ItemBlob: null, | ||
ItemFolder: { | ||
id: expect.any(Number), | ||
color: '#123456', | ||
}, | ||
ItemDocs: null, | ||
}); | ||
|
||
expect(responseBlob.statusCode).toBe(200); | ||
expect(responseBlob.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'test1.txt', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'text/plain', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
ItemBlob: { | ||
id: expect.any(Number), | ||
blobUrl: 'https://example.com/test1.txt', | ||
}, | ||
ItemFolder: null, | ||
ItemDocs: null, | ||
}); | ||
|
||
expect(responseDocs.statusCode).toBe(200); | ||
expect(responseDocs.json()).toEqual({ | ||
id: expect.any(Number), | ||
name: 'Docser', | ||
parentId: null, | ||
ownerId: user.id, | ||
mimeType: 'application/vnd.cloudstore.docs', | ||
createdAt: expect.any(String), | ||
deletedAt: null, | ||
updatedAt: expect.any(String), | ||
ItemBlob: null, | ||
ItemFolder: null, | ||
ItemDocs: { | ||
id: expect.any(Number), | ||
text: 'Docs text here!', | ||
}, | ||
}); | ||
}); | ||
|
||
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
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