-
Notifications
You must be signed in to change notification settings - Fork 10
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
Showing
4 changed files
with
75 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 +1,24 @@ | ||
import { pathExists } from "fs-extra"; | ||
import { InteractionsModule } from "../../../interactions/interactions.module"; | ||
import { AppLogsService } from "../../../modules/app-logs/app-logs.service"; | ||
import { StructuresModule } from "../../../structures/structure.module"; | ||
import { UsersModule } from "../../../users/users.module"; | ||
import { AppTestContext, AppTestHelper } from "../../../util/test"; | ||
import { | ||
AppTestContext, | ||
AppTestHelper, | ||
AppTestHttpClient, | ||
} from "../../../util/test"; | ||
import { UsagerDocsController } from "../usager-docs.controller"; | ||
import { resolve } from "path"; | ||
import { TESTS_USERS_STRUCTURE } from "../../../_tests"; | ||
import { UsagerDoc } from "../../../_common/model"; | ||
import { HttpStatus } from "@nestjs/common"; | ||
|
||
describe("Document Controller", () => { | ||
let controller: UsagerDocsController; | ||
|
||
let context: AppTestContext; | ||
let doc: UsagerDoc; | ||
|
||
beforeAll(async () => { | ||
context = await AppTestHelper.bootstrapTestApp({ | ||
|
@@ -17,12 +27,54 @@ describe("Document Controller", () => { | |
providers: [AppLogsService], | ||
}); | ||
controller = context.module.get<UsagerDocsController>(UsagerDocsController); | ||
|
||
const authInfo = TESTS_USERS_STRUCTURE.BY_EMAIL["[email protected]"]; | ||
|
||
await AppTestHelper.authenticateStructure(authInfo, { context }); | ||
}); | ||
|
||
afterAll(async () => { | ||
await AppTestHelper.tearDownTestApp(context); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
it(`✅ Ajout d'un fichier`, async () => { | ||
const importFilePath = resolve( | ||
__dirname, | ||
"../../../_static/usager-docs-test/logo-beta.jpeg" | ||
); | ||
|
||
expect(await pathExists(importFilePath)).toBeTruthy(); | ||
|
||
const headers: { [name: string]: string } = {}; | ||
headers["Content-Type"] = "multipart/form-data"; | ||
|
||
const response = await AppTestHttpClient.post("/docs/1", { | ||
headers, | ||
attachments: { file: importFilePath }, | ||
fields: { | ||
label: "Logo beta-gouv", | ||
}, | ||
context, | ||
}); | ||
|
||
expect(response.status).toBe(HttpStatus.OK); | ||
|
||
expect(response.body.length).toEqual(2); | ||
expect(response.body[1].createdBy).toEqual("Patrick Roméro"); | ||
expect(response.body[1].filetype).toEqual("image/jpeg"); | ||
expect(response.body[1].label).toEqual("Logo beta-gouv"); | ||
|
||
doc = response.body[1]; | ||
}); | ||
it(`✅ Suppression d'un fichier`, async () => { | ||
const response = await AppTestHttpClient.delete(`/docs/1/${doc.uuid}`, { | ||
context, | ||
}); | ||
|
||
expect(response.status).toBe(HttpStatus.OK); | ||
}); | ||
}); |
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