-
Notifications
You must be signed in to change notification settings - Fork 6
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
5 changed files
with
2,628 additions
and
42 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,54 @@ | ||
import { FiscalCode } from "italia-ts-commons/lib/strings"; | ||
|
||
import { canWriteMessage } from "../handler"; | ||
import { UserGroup } from "io-functions-commons/dist/src/utils/middlewares/azure_api_auth"; | ||
|
||
const aFiscalCode = "FRLFRC74E04B157I" as FiscalCode; | ||
|
||
describe("canWriteMessage", () => { | ||
it("should respond with ResponseErrorForbiddenNotAuthorizedForProduction when service is in no group", () => { | ||
const response = canWriteMessage( | ||
new Set(), | ||
new Set([aFiscalCode]), | ||
aFiscalCode | ||
); | ||
expect(response.isLeft()).toBeTruthy(); | ||
if (response.isLeft()) { | ||
expect(response.value.kind).toEqual( | ||
"IResponseErrorForbiddenNotAuthorizedForProduction" | ||
); | ||
} | ||
}); | ||
|
||
it("should respond with ResponseErrorForbiddenNotAuthorizedForRecipient when service is trying to send message to an unauthorized recipient", () => { | ||
const response = canWriteMessage( | ||
new Set([UserGroup.ApiLimitedMessageWrite]), | ||
new Set([]), | ||
aFiscalCode | ||
); | ||
expect(response.isLeft()).toBeTruthy(); | ||
if (response.isLeft()) { | ||
expect(response.value.kind).toEqual( | ||
"IResponseErrorForbiddenNotAuthorizedForRecipient" | ||
); | ||
} | ||
}); | ||
|
||
it("should pass when service is trying to send message to an authorized recipient", () => { | ||
const response = canWriteMessage( | ||
new Set([UserGroup.ApiLimitedMessageWrite]), | ||
new Set([aFiscalCode]), | ||
aFiscalCode | ||
); | ||
expect(response.isRight()).toBeTruthy(); | ||
}); | ||
|
||
it("should pass when service can send messages to any recipient", () => { | ||
const response = canWriteMessage( | ||
new Set([UserGroup.ApiMessageWrite]), | ||
new Set([]), | ||
aFiscalCode | ||
); | ||
expect(response.isRight()).toBeTruthy(); | ||
}); | ||
}); |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
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.