-
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 pull request #4 from fga-eps-mds/develop
Develop
- Loading branch information
Showing
25 changed files
with
932 additions
and
39 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.ignore/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Front Receive</title> | ||
<script src="script.js"></script> | ||
</head> | ||
<body> | ||
|
||
<input type="text" name="id" id="id" placeholder="Name"> | ||
<button onclick="receiveFile()">Receive</button> | ||
|
||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const receiveFile = () => { | ||
const id = document.getElementById('id').value; | ||
|
||
const formData = new FormData(); | ||
formData.append('id', id); | ||
|
||
// Get file id using XMLHttpRequest | ||
const xhr = new XMLHttpRequest(); | ||
|
||
xhr.open('GET', 'http://localhost:3004/tutorials/'+id, true); | ||
xhr.send(formData); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4 && this.status == 200) { | ||
const response = JSON.parse(this.responseText); | ||
|
||
let blob1 = new Blob([new Uint8Array(response.data.data)],{type:'application/pdf'}) | ||
|
||
let blobUrl = URL.createObjectURL(blob1); | ||
|
||
let link = document.createElement('a'); | ||
|
||
if('download' in link){ | ||
link.type = 'download' | ||
link.href = blobUrl | ||
link.download = response.filename | ||
link.click() | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Front send</title> | ||
<script src="script.js"></script> | ||
</head> | ||
<body> | ||
<form action="http://localhost:3004/tutorials" method="post" enctype="multipart/form-data"> | ||
<input type="text" name="name" id="name" placeholder="Name"> | ||
<input type="text" name="category_id" id="category_id" placeholder="Id da Categoria"> | ||
<input type="file" name="file" id="file"> | ||
<button type="submit">Send</button> | ||
</form> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,104 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CategoriesController } from './categories.controller'; | ||
import { CategoriesService } from './categories.service'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { CreateCategoryDto } from './dto/create-category.dto'; | ||
import { UpdateCategoryDto } from './dto/update-category.dto'; | ||
import { CacheModule } from '@nestjs/common'; | ||
|
||
|
||
describe('CategoriesController', () => { | ||
let controller: CategoriesController; | ||
let categoriesController: CategoriesController; | ||
|
||
const mockUuid = uuidv4(); | ||
|
||
const mockCreateCategoryDto: CreateCategoryDto = { | ||
name: 'mock_category', | ||
}; | ||
|
||
const mockUpdteCategoryDto: UpdateCategoryDto = { | ||
name: 'new_mock_category', | ||
}; | ||
|
||
const mockCategoriesService = { | ||
createCategory: jest.fn((dto) => { | ||
return { | ||
...dto, | ||
}; | ||
}), | ||
findCategoryById: jest.fn((id) => { | ||
return { | ||
...mockCreateCategoryDto, | ||
id, | ||
}; | ||
}), | ||
updateCategory: jest.fn((dto, id) => { | ||
return { | ||
...mockCreateCategoryDto, | ||
...dto, | ||
id, | ||
}; | ||
}), | ||
deleteCategory: jest.fn((id) => { | ||
return; | ||
}), | ||
findCategories: jest.fn(() => { | ||
return [{ ...mockCreateCategoryDto }]; | ||
}), | ||
}; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [CategoriesController], | ||
providers: [CategoriesService], | ||
imports: [CacheModule.register()], | ||
}).overrideProvider(CategoriesService) | ||
.useValue({}) | ||
}) | ||
.overrideProvider(CategoriesService) | ||
.useValue(mockCategoriesService) | ||
.compile(); | ||
|
||
controller = module.get<CategoriesController>(CategoriesController); | ||
categoriesController = | ||
module.get<CategoriesController>(CategoriesController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
expect(categoriesController).toBeDefined(); | ||
}); | ||
|
||
it('should create a new category with success', async () => { | ||
const dto = mockCreateCategoryDto; | ||
const response = await categoriesController.createCategory(dto); | ||
|
||
expect(response).toMatchObject({ ...dto }); | ||
}); | ||
|
||
it('should return an category with success', async () => { | ||
const categoryId = mockUuid; | ||
const response = await categoriesController.findCategoryById(categoryId); | ||
|
||
expect(response).toMatchObject({ id: categoryId }); | ||
}); | ||
|
||
it('should return all categories with success', async () => { | ||
const response = await categoriesController.findCategories(); | ||
|
||
expect(response.length).toBeGreaterThan(0); | ||
expect(response).toEqual([{ ...mockCreateCategoryDto }]); | ||
}); | ||
|
||
it('should update an category with success', async () => { | ||
const categoryId = mockUuid; | ||
const dto = mockUpdteCategoryDto; | ||
const response = await categoriesController.updateCategory(dto, categoryId); | ||
|
||
expect(response).toMatchObject({ ...dto, id: categoryId }); | ||
}); | ||
|
||
it('should delete an category with success', async () => { | ||
const categoryId = mockUuid; | ||
const successMessage = 'Categoria removida com sucesso'; | ||
const response = await categoriesController.deleteCategory(categoryId); | ||
|
||
expect(response).toBe(successMessage); | ||
}); | ||
|
||
}); |
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.