-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AUT-2164: Create new service to check for fraudulent emails
- Loading branch information
1 parent
e972401
commit 3020999
Showing
5 changed files
with
98 additions
and
7 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
41 changes: 41 additions & 0 deletions
41
src/components/check-email-fraud-block/checkEmailFraudBlockService.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,41 @@ | ||
import { | ||
createApiResponse, | ||
getRequestConfig, | ||
Http, | ||
http, | ||
} from "../../utils/http"; | ||
import { API_ENDPOINTS } from "../../app.constants"; | ||
import { ApiResponseResult } from "../../types"; | ||
import { | ||
CheckEmailFraudBlockInterface, | ||
CheckEmailFraudBlockResponse, | ||
} from "./types"; | ||
|
||
export function checkEmailFraudBlockService( | ||
axios: Http = http | ||
): CheckEmailFraudBlockInterface { | ||
const checkEmailFraudBlock = async function ( | ||
email: string, | ||
sessionId: string, | ||
sourceIp: string, | ||
clientSessionId: string, | ||
persistentSessionId: string | ||
): Promise<ApiResponseResult<CheckEmailFraudBlockResponse>> { | ||
const response = await axios.client.post<CheckEmailFraudBlockResponse>( | ||
API_ENDPOINTS.CHECK_EMAIL_FRAUD_BLOCK, | ||
{ | ||
email: email.toLowerCase(), | ||
}, | ||
getRequestConfig({ | ||
sessionId: sessionId, | ||
sourceIp: sourceIp, | ||
clientSessionId: clientSessionId, | ||
persistentSessionId: persistentSessionId, | ||
}) | ||
); | ||
return createApiResponse<CheckEmailFraudBlockResponse>(response); | ||
}; | ||
return { | ||
checkEmailFraudBlock, | ||
}; | ||
} |
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 @@ | ||
import { ApiResponseResult, DefaultApiResponse } from "../../types"; | ||
|
||
export interface CheckEmailFraudBlockInterface { | ||
checkEmailFraudBlock: ( | ||
email: string, | ||
sessionId: string, | ||
sourceIp: string, | ||
clientSessionId: string, | ||
persistentSessionId: string | ||
) => Promise<ApiResponseResult<CheckEmailFraudBlockResponse>>; | ||
} | ||
|
||
export interface CheckEmailFraudBlockResponse extends DefaultApiResponse { | ||
email: string; | ||
isBlockedStatus: string; | ||
} |
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,18 +1,14 @@ | ||
import request from "supertest"; | ||
import { describe } from "mocha"; | ||
import { expect, sinon } from "../../../../test/utils/test-utils"; | ||
import nock = require("nock"); | ||
import * as cheerio from "cheerio"; | ||
import decache from "decache"; | ||
import { | ||
API_ENDPOINTS, | ||
HTTP_STATUS_CODES, | ||
PATH_NAMES, | ||
} from "../../../app.constants"; | ||
import { API_ENDPOINTS, HTTP_STATUS_CODES, PATH_NAMES } from "../../../app.constants"; | ||
import { CheckReauthServiceInterface } from "../../check-reauth-users/types"; | ||
import { AxiosResponse } from "axios"; | ||
import { createApiResponse } from "../../../utils/http"; | ||
import { DefaultApiResponse } from "../../../types"; | ||
import nock = require("nock"); | ||
|
||
describe("Integration::enter email", () => { | ||
let token: string | string[]; | ||
|
@@ -167,6 +163,13 @@ describe("Integration::enter email", () => { | |
email: "[email protected]", | ||
doesUserExist: true, | ||
}); | ||
nock(baseApi) | ||
.post(API_ENDPOINTS.CHECK_EMAIL_FRAUD_BLOCK) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.OK, { | ||
email: "[email protected]", | ||
isBlockedStatus: "Pending", | ||
}); | ||
|
||
request(app) | ||
.post(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
|
@@ -185,6 +188,13 @@ describe("Integration::enter email", () => { | |
email: "[email protected]", | ||
doesUserExist: false, | ||
}); | ||
nock(baseApi) | ||
.post(API_ENDPOINTS.CHECK_EMAIL_FRAUD_BLOCK) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.OK, { | ||
email: "[email protected]", | ||
isBlockedStatus: "Pending", | ||
}); | ||
|
||
request(app) | ||
.post(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
|
@@ -236,6 +246,14 @@ describe("Integration::enter email", () => { | |
doesUserExist: true, | ||
}); | ||
|
||
nock(baseApi) | ||
.post(API_ENDPOINTS.CHECK_EMAIL_FRAUD_BLOCK) | ||
.once() | ||
.reply(HTTP_STATUS_CODES.OK, { | ||
email: "[email protected]", | ||
isBlockedStatus: "Pending", | ||
}); | ||
|
||
request(app) | ||
.post(PATH_NAMES.ENTER_EMAIL_SIGN_IN) | ||
.type("form") | ||
|