Merge pull request #23 from valitydev/ft/fix-tests

Add wb-list tests
This commit is contained in:
struga 2022-06-21 15:04:07 +03:00 committed by GitHub
commit 89e561d26e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 318 additions and 128 deletions

View File

@ -251,7 +251,7 @@ services:
restart: unless-stopped
fb-management:
image: ghcr.io/valitydev/fraudbusters-management:sha-cc49e98
image: ghcr.io/valitydev/fraudbusters-management:sha-1c77dae
hostname: fb-management
container_name: fb-management
mem_limit: 400m
@ -349,7 +349,7 @@ services:
- ./log-java:/opt/fraudbusters-warehouse/tmp
fraudbusters-ui:
image: ghcr.io/valitydev/fraudbusters-ui:sha-831538a
image: ghcr.io/valitydev/fraudbusters-ui:sha-9161e0e
hostname: fraudbusters-ui
container_name: fraudbusters-ui
environment:

View File

@ -4,6 +4,7 @@ module.exports = {
templatePath: process.env.FB_M_TEMPLATE_PATH || '/fb-management/v1/payments-templates',
referencePath: process.env.FB_M_REFEREBCE_PATH || '/fb-management/v1/payments-references',
groupPath: process.env.FB_M_GROUP_PATH || '/fb-management/v1/payments-groups',
listsPath: process.env.FB_M_GROUP_PATH || '/fb-management/v1/payments-lists',
},
fbApi: {
url: process.env.FB_API_URL || "http://fraudbusters-api:8080",

View File

@ -15,7 +15,6 @@ const SHOP_ID = "shop-aggr-id";
const PARTY_ID = "party-aggr-id";
const CARD_TOKEN = "aggr_test_token";
const AGGR_FINGERPRINT = "aggr_fingerprint";
const EMAIL = "test_unique@vality.dev";
const TEMPLATE = "rule: unique(\"ip\", \"email\", 30, days, \"party_id\", \"shop_id\") > 1 " +
" OR count(\"card_token\", 30, days, \"party_id\", \"shop_id\") > 2 " +
@ -29,7 +28,10 @@ function generateIp(prefix) {
function generateCardToken() {
return CARD_TOKEN + Math.floor(Math.random() * 999);
}
function generateEmail(prefix) {
return prefix + Math.floor(Math.random() * 999);
}
function generateFingerprint() {
@ -61,15 +63,17 @@ describe('Test for check aggregates', function () {
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("array");
res.body.length.should.be.eql(1);
res.body.should.does.include(PARTY_ID + "_" + SHOP_ID);
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.length.should.be.eql(1);
res.body.result.should.does.include(PARTY_ID + "_" + SHOP_ID);
}, PARTY_ID, SHOP_ID, TEMPLATE_ID);
});
let ipUniq = generateIp("192.1.1.");
let cardToken = generateCardToken();
let fingerprint = generateFingerprint();
let uniqueEmail = generateEmail("test_unique_1");
it('it should inspect that payment have HIGH risk for UNIQUE', function (done) {
inspectorService.inspectPayment(done,
@ -80,7 +84,7 @@ describe('Test for check aggregates', function () {
res.body.should.have.property("result");
res.body.result.should.equal('high');
},
EMAIL, ipUniq, fingerprint, cardToken, PARTY_ID, SHOP_ID);
uniqueEmail, ipUniq, fingerprint, cardToken, PARTY_ID, SHOP_ID);
});
it('it should upload payment to history', function (done) {
@ -88,10 +92,10 @@ describe('Test for check aggregates', function () {
(res) => {
res.should.have.status(201);
},
status, EMAIL, ipUniq, cardToken, fingerprint, PARTY_ID, SHOP_ID);
status, uniqueEmail, ipUniq, cardToken, fingerprint, PARTY_ID, SHOP_ID);
});
const emailUnique = 'test_unique_2@vality.dev';
const anotherUniqueEmail = generateEmail('test_unique_2');
it('it should inspect that payment have FATAL risk for UNIQUE', function (done) {
inspectorService.inspectPayment(done,
@ -101,18 +105,18 @@ describe('Test for check aggregates', function () {
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.should.equal('fatal');
}, emailUnique, ipUniq, fingerprint, cardToken, PARTY_ID, SHOP_ID);
}, anotherUniqueEmail, ipUniq, fingerprint, cardToken, PARTY_ID, SHOP_ID);
});
it('it should upload payment to history', function (done) {
paymentService.uploadPayment(done, (res) => {
res.should.have.status(201);
},
status, emailUnique, ipUniq, cardToken, fingerprint, PARTY_ID, SHOP_ID);
status, anotherUniqueEmail, ipUniq, cardToken, fingerprint, PARTY_ID, SHOP_ID);
});
const ipCount = generateIp("192.1.2.");
const emailCount = "test_count@vality.dev";
const emailCount = generateEmail('test_count');
it('it should inspect that payment have FATAL risk for COUNT', function (done) {
inspectorService.inspectPayment(done,
@ -125,7 +129,7 @@ describe('Test for check aggregates', function () {
}, emailCount, ipCount, fingerprint, cardToken, PARTY_ID, SHOP_ID);
});
const emailSum = "test_sum@vality.dev";
const emailSum = generateEmail('test_sum');
let cardTokenSum = generateCardToken();
it('it should inspect that payment have FATAL risk for SUM', function (done) {

View File

@ -40,9 +40,9 @@ describe('Test for check geo ip service', function () {
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("array");
res.body.length.should.be.eql(1);
res.body.should.does.include(PARTY_ID + "_" + SHOP_ID);
res.body.should.be.a("object");
res.body.result.length.should.be.eql(1);
res.body.result.should.does.include(PARTY_ID + "_" + SHOP_ID);
}, PARTY_ID, SHOP_ID, TEMPLATE_ID);
});

View File

@ -48,7 +48,7 @@ module.exports.create =
},
payerType: "payment_resource",
tokenMobileProvider: null,
createdAt: Date.now() / 1000,
createdAt: Math.floor(Date.now() / 1000),
description: "Test product"
};
}

View File

@ -22,7 +22,7 @@ module.exports.uploadPayment = function (done, checkResponse, status, email, ip,
shopId
),
paymentStatus: status,
eventTime: "2019-08-24T14:15:22Z"
eventTime: (new Date()).toJSON(),
}
]
};

View File

@ -0,0 +1,41 @@
const chai = require("chai");
const config = require("../../config");
const chaiHttp = require("chai-http");
const should = chai.should();
chai.use(chaiHttp);
const LISTS_PATH = config.fbManagement.listsPath;
const FB_MGMNT_URL = config.fbManagement.url;
module.exports.create = function (done, checkResponse, listType, listName, partyId, shopId, value, countInfo) {
let LIST_TEMPLATE = {
listType: listType,
records: [
{
countInfo: countInfo,
listRecord: {
listName: listName,
partyId: partyId,
shopId: shopId,
value: value
}
}
]
};
chai.request(FB_MGMNT_URL)
.post(LISTS_PATH)
.send(LIST_TEMPLATE)
.end(function (err, res) {
if (err) {
console.log(err.text);
console.log(res);
done(err);
}
should.not.exist(err);
should.not.exist(res.body.errors)
checkResponse(res);
done()
});
}

View File

@ -37,9 +37,9 @@ describe('Test for simple rule inspection', function () {
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("array");
res.body.length.should.be.eql(1);
res.body.should.does.include(PARTY_ID + "_" + SHOP_ID);
res.body.should.be.a("object");
res.body.result.length.should.be.eql(1);
res.body.result.should.does.include(PARTY_ID + "_" + SHOP_ID);
}, PARTY_ID, SHOP_ID, TEMPLATE_ID);
});

View File

@ -13,9 +13,13 @@ const testTimeout = config.testTimeout;
const TEMPLATE_ID = "test-trustes-templ-id";
const SHOP_ID = "shop-trusted-id";
const PARTY_ID = "party-trusted-id";
const CARD_TOKEN = "trusted_test_token";
const CARD_TOKEN = "trusted_test_token_";
const TEMPLATE = "rule: isTrusted(paymentsConditions(condition(\"RUB\" ,1 ,1 ,1 ))) -> accept;";
function generateCardToken() {
return CARD_TOKEN + Math.floor(Math.random() * 999);
}
describe('Test for check trusted tokens', function () {
this.timeout(testTimeout);
@ -42,12 +46,14 @@ describe('Test for check trusted tokens', function () {
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("array");
res.body.length.should.be.eql(1);
res.body.should.does.include(PARTY_ID + "_" + SHOP_ID);
res.body.should.be.a("object");
res.body.result.length.should.be.eql(1);
res.body.result.should.does.include(PARTY_ID + "_" + SHOP_ID);
}, PARTY_ID, SHOP_ID, TEMPLATE_ID);
});
let cardToken = generateCardToken();
it('it should inspect that payment have default HIGH risk', function (done) {
inspectorService.inspectPayment(done,
(res) => {
@ -60,7 +66,7 @@ describe('Test for check trusted tokens', function () {
"test@mail.ru",
"123.123.123.123",
"xxxxx",
CARD_TOKEN,
cardToken,
PARTY_ID,
SHOP_ID,
100);
@ -74,7 +80,7 @@ describe('Test for check trusted tokens', function () {
"captured",
"test@mail.ru",
"123.123.123.123",
CARD_TOKEN,
cardToken,
"xxxxx",
PARTY_ID,
SHOP_ID,
@ -89,7 +95,7 @@ describe('Test for check trusted tokens', function () {
"captured",
"test@mail.ru",
"123.123.123.123",
CARD_TOKEN,
cardToken,
"xxxxx",
PARTY_ID,
SHOP_ID,
@ -97,7 +103,7 @@ describe('Test for check trusted tokens', function () {
});
it('it should inspect that payment have LOW risk', function (done) {
inspectorService.inspectPayment(done,
setTimeout(() => inspectorService.inspectPayment(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
@ -108,9 +114,11 @@ describe('Test for check trusted tokens', function () {
"test@mail.ru",
"123.123.123.123",
"xxxxx",
CARD_TOKEN,
cardToken,
PARTY_ID,
SHOP_ID,
1000);
1000),
5000);
});
});

View File

@ -3,122 +3,114 @@ const chaiHttp = require("chai-http");
const should = chai.should();
chai.use(chaiHttp);
const config = require("../config");
const templateService = require("./service/template_service.js");
const inspectorService = require("./service/inspector_service.js");
const listsService = require("./service/wb_list_service.js");
const paymentService = require("./service/payment_service.js");
const FB_MGMNT_URL = config.fbManagement.url;
const TEMPLATE_PATH = config.fbManagement.templatePath;
const GROUP_PATH = config.fbManagement.groupPath;
const testTimeout = config.testTimeout;
const templateId = "test-wb-templ-id";
const templateRefId = "test-wb-ref-id";
const shopId = "shop-wb-id";
const partyId = "party-wb-id";
const GROUP_ID = "group_1";
const IN_WHITE_lIST_TEMPLATE_ID = "white-list-template-id";
const IN_GREY_LIST_TEMPLATE_ID = "grey-list-template-id";
const IN_BLACK_LIST_TEMPLATE_ID = "black-list-template-id";
const GROUP_REFERENCE_ID = "test-wb-ref-id";
const SHOP_ID = "shop-wb-id";
const PARTY_ID = "party-wb-id";
const GROUP_ID = "group_id";
const IN_WHITE_LIST_TEMPLATE = "rule: inWhiteList(\"email\") -> accept;";
const IN_GREY_LIST_TEMPLATE = "rule: inGreyList(\"card_token\") -> accept;";
const IN_BLACK_LIST_TEMPLATE = "rule: inBlackList(\"card_token\") -> decline;"
const CARD_TOKEN = "wb_test_token_";
function generateCardToken() {
return CARD_TOKEN + Math.floor(Math.random() * 999);
}
const EMAIL = "test@mail.ru" + Math.floor(Math.random() * 999);
function getNowDatePlusOneDay() {
return new Date(Date.now() + 24 * 60 * 60 * 1000);
}
describe('Test for check white, black and grey tokens', function () {
this.timeout(testTimeout);
it.skip('it should create a new template_1', function (done) {
let TEST_TEMPLATE = {
id: templateId + "_1",
lastUpdateDate: "2022-04-15T10:30:00",
modifiedByUser: "test-user",
template: "rule: " +
"inWhiteList(\"email\")" +
" -> accept;"
};
chai.request(FB_MGMNT_URL)
.post(TEMPLATE_PATH)
.send(TEST_TEMPLATE)
.end(function (err, res) {
if (err) {
console.log(err.text);
done(err);
}
should.not.exist(err);
it('it should create a new white list template', function (done) {
templateService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("errors");
res.body.should.have.property("id");
res.body.id.should.equal(TEST_TEMPLATE.id);
done()
});
res.body.should.have.property("template");
res.body.id.should.not.be.null;
res.body.template.should.not.be.null;
res.body.id.should.equal(IN_WHITE_lIST_TEMPLATE_ID);
res.body.template.should.equal(IN_WHITE_LIST_TEMPLATE);
},
IN_WHITE_LIST_TEMPLATE,
IN_WHITE_lIST_TEMPLATE_ID);
});
it.skip('it should create a new template_2', function (done) {
let TEST_TEMPLATE = {
id: templateId + "_2",
lastUpdateDate: "2022-04-15T10:30:00",
modifiedByUser: "test-user",
template: "rule: " +
"inGreyList(\"cardToken\") " +
" -> accept;"
};
chai.request(FB_MGMNT_URL)
.post(TEMPLATE_PATH)
.send(TEST_TEMPLATE)
.end(function (err, res) {
if (err) {
console.log(err.text);
done(err);
}
should.not.exist(err);
it('it should create a new grey list template', function (done) {
templateService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("errors");
res.body.should.have.property("id");
res.body.id.should.equal(TEST_TEMPLATE.id);
done()
});
res.body.should.have.property("template");
res.body.id.should.not.be.null;
res.body.template.should.not.be.null;
res.body.id.should.equal(IN_GREY_LIST_TEMPLATE_ID);
res.body.template.should.equal(IN_GREY_LIST_TEMPLATE);
},
IN_GREY_LIST_TEMPLATE,
IN_GREY_LIST_TEMPLATE_ID);
});
it.skip('it should create a new template_3', function (done) {
let TEST_TEMPLATE = {
id: templateId + "_3",
lastUpdateDate: "2022-04-15T10:30:00",
modifiedByUser: "test-user",
template: "rule: " +
"inBlackList(\"cardToken\")" +
" -> decline;"
};
chai.request(FB_MGMNT_URL)
.post(TEMPLATE_PATH)
.send(TEST_TEMPLATE)
.end(function (err, res) {
if (err) {
console.log(err.text);
done(err);
}
should.not.exist(err);
it('it should create a new black list template', function (done) {
templateService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("errors");
res.body.should.have.property("id");
res.body.id.should.equal(TEST_TEMPLATE.id);
done()
});
res.body.should.have.property("template");
res.body.id.should.not.be.null;
res.body.template.should.not.be.null;
res.body.id.should.equal(IN_BLACK_LIST_TEMPLATE_ID);
res.body.template.should.equal(IN_BLACK_LIST_TEMPLATE);
},
IN_BLACK_LIST_TEMPLATE,
IN_BLACK_LIST_TEMPLATE_ID);
});
it.skip('it should create a new group for templates', function (done) {
it('it should create a new group for list templates', function (done) {
let TEST_GROUP = {
groupId: GROUP_ID,
modifiedByUser: "test-user",
priorityTemplates: [
{
id: templateId + "_1",
id: IN_WHITE_lIST_TEMPLATE_ID,
lastUpdateTime: "2019-08-24T14:15:22Z",
priority: 0
},
{
id: templateId + "_2",
lastUpdateTime: "2019-08-24T14:15:22Z",
priority: 1
},
{
id: templateId + "_3",
id: IN_GREY_LIST_TEMPLATE_ID,
lastUpdateTime: "2019-08-24T14:15:22Z",
priority: 2
},
{
id: IN_BLACK_LIST_TEMPLATE_ID,
lastUpdateTime: "2019-08-24T14:15:22Z",
priority: 1
}]
};
@ -135,15 +127,14 @@ describe('Test for check white, black and grey tokens', function () {
});
});
it.skip('it should create a new reference for group', function (done) {
it('it should create a new reference for group', function (done) {
let TEST_GROUP = [{
groupId: GROUP_ID,
id: templateRefId,
id: GROUP_REFERENCE_ID,
lastUpdateDate: "2022-04-15T10:30:30",
modifiedByUser: "test-user",
shopId: shopId,
partyId: partyId,
templateId: templateId
shopId: SHOP_ID,
partyId: PARTY_ID
}];
chai.request(FB_MGMNT_URL)
@ -161,4 +152,149 @@ describe('Test for check white, black and grey tokens', function () {
});
});
let cardToken = generateCardToken();
it('it should inspect that payment have HIGH risk by default result', function (done) {
inspectorService.inspectPayment(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.should.equal('high');
},
EMAIL,
"123.123.123.123",
"xxxxx",
cardToken,
PARTY_ID,
SHOP_ID,
1000);
});
it('it should create a new row in list white', function (done) {
listsService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.length.should.be.eql(1);
},
"white",
"EMAIL",
PARTY_ID,
SHOP_ID,
EMAIL);
});
it('it should inspect that payment have LOW risk by white list template', function (done) {
setTimeout(() => inspectorService.inspectPayment(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.should.equal('low');
},
EMAIL,
"123.123.123.123",
"xxxxx",
cardToken,
PARTY_ID,
SHOP_ID,
1000),
10000);
});
it('it should create a new row in grey list', function (done) {
listsService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.length.should.be.eql(1);
},
"grey",
"CARD_TOKEN",
PARTY_ID,
SHOP_ID,
cardToken,
{
"count": 0,
"endCountTime": getNowDatePlusOneDay().toJSON(),
"startCountTime": (new Date()).toJSON()
});
});
it('it should inspect that payment have LOW risk by grey list template, first gery list attempt', function (done) {
setTimeout(() => inspectorService.inspectPayment(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.should.equal('low');
},
EMAIL + 'x',
"123.123.123.123",
"xxxxx",
cardToken,
PARTY_ID,
SHOP_ID,
1000), 10000);
});
it('it should upload payment to history for test grey list', function (done) {
paymentService.uploadPayment(done,
(res) => {
res.should.have.status(201);
},
"captured",
EMAIL + 'x',
"123.123.123.123",
cardToken,
"xxxxx",
PARTY_ID,
SHOP_ID,
"invoice_id_1.1");
});
it('it should create a new row in black list', function (done) {
listsService.create(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.length.should.be.eql(1);
},
"black",
"CARD_TOKEN",
PARTY_ID,
SHOP_ID,
cardToken);
});
it('it should inspect that payment have FATAL risk by black list template', function (done) {
setTimeout(() => inspectorService.inspectPayment(done,
(res) => {
res.should.have.status(200);
res.should.be.json;
res.body.should.be.a("object");
res.body.should.have.property("result");
res.body.result.should.equal('fatal');
},
EMAIL + 'x',
"123.123.123.123",
"xxxxx",
cardToken,
PARTY_ID,
SHOP_ID,
1000), 10000);
});
});