-
Notifications
You must be signed in to change notification settings - Fork 20
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 #2678 from MTES-MCT/master
Master -> dev
- Loading branch information
Showing
4 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
back/src/common/middlewares/__tests__/graphqlBodyParser.test.ts
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,37 @@ | ||
import express, { json } from "express"; | ||
import supertest from "supertest"; | ||
import { graphqlBodyParser } from "../graphqlBodyParser"; | ||
|
||
describe("graphqlBodyParser", () => { | ||
const app = express(); | ||
const graphQLPath = "/"; | ||
app.use(json()); | ||
app.use(graphQLPath, graphqlBodyParser); | ||
|
||
app.get("/hello", (req, res) => { | ||
res.status(200).send("world"); | ||
}); | ||
app.post(graphQLPath, (req, res) => { | ||
// Return body | ||
res.status(200).send({ reqBody: req.body }); | ||
}); | ||
|
||
const request = supertest(app); | ||
|
||
it("should convert JSON encoded variables to JSON", async () => { | ||
const response = await request | ||
.post(graphQLPath) | ||
.send({ query: "{ __typename }", variables: '{ "foo": 1 }' }); | ||
|
||
expect(response.body.reqBody.variables.foo).toBe(1); | ||
}); | ||
|
||
it("should convert application/graphql requests", async () => { | ||
const response = await request | ||
.post(graphQLPath) | ||
.set("Content-Type", "application/graphql") | ||
.send("{ __typename }"); | ||
|
||
expect(response.body.reqBody.query).toBe("{ __typename }"); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -291,6 +291,53 @@ describe("sirenifyFormInput", () => { | |
searchResults[intermediary2.company.siret!].address | ||
); | ||
}); | ||
|
||
it("should overwrite `name` and `address` if company is not diffusible but registered in Trackdéchets", async () => { | ||
const emitter = await userWithCompanyFactory("MEMBER", { | ||
siret: "90398556200011", | ||
orgId: "90398556200011" | ||
}); | ||
|
||
function searchResult(companyName: string) { | ||
return { | ||
name: companyName, | ||
address: `Adresse ${companyName}`, | ||
statutDiffusionEtablissement: "N", | ||
isRegistered: true | ||
} as CompanySearchResult; | ||
} | ||
|
||
const searchResults = { | ||
[emitter.company.siret!]: searchResult("émetteur") | ||
}; | ||
|
||
searchCompanySpy.mockImplementation((clue: string) => { | ||
return Promise.resolve(searchResults[clue]); | ||
}); | ||
|
||
const formInput: CreateFormInput = { | ||
emitter: { | ||
company: { | ||
siret: "90398556200011" | ||
} | ||
} | ||
}; | ||
|
||
const sirenified = await sirenifyFormInput(formInput, { | ||
email: "[email protected]", | ||
auth: AuthType.Bearer | ||
} as Express.User); | ||
|
||
expect(sirenified).toMatchObject({ | ||
emitter: { | ||
company: { | ||
name: "émetteur", | ||
address: "Adresse émetteur", | ||
siret: "90398556200011" | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe("sirenifyResealedFormInput", () => { | ||
|