@studyportals/campaign-management-api-interface 0.13.1 → 0.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{index.ts → index.d.ts} +1 -21
- package/index.js +20 -0
- package/index.js.map +1 -0
- package/package.json +3 -3
- package/src/auditor-campaign-management-api.client.d.ts +12 -0
- package/src/auditor-campaign-management-api.client.js +56 -0
- package/src/auditor-campaign-management-api.client.js.map +1 -0
- package/src/campaign-management-api.client.d.ts +13 -0
- package/src/campaign-management-api.client.js +68 -0
- package/src/campaign-management-api.client.js.map +1 -0
- package/src/domain/auditor/campaigns/geotargeting.entities.d.ts +14 -0
- package/src/domain/auditor/campaigns/geotargeting.entities.js +11 -0
- package/src/domain/auditor/campaigns/geotargeting.entities.js.map +1 -0
- package/src/domain/auditor/enums/auditor-entity-type.enum.d.ts +3 -0
- package/src/domain/auditor/enums/auditor-entity-type.enum.js +8 -0
- package/src/domain/auditor/enums/auditor-entity-type.enum.js.map +1 -0
- package/src/domain/auditor/enums/{auditor-operation.enum.ts → auditor-operation.enum.d.ts} +2 -2
- package/src/domain/auditor/enums/auditor-operation.enum.js +14 -0
- package/src/domain/auditor/enums/auditor-operation.enum.js.map +1 -0
- package/src/domain/auditor/get-auditor.dto.d.ts +13 -0
- package/src/domain/auditor/get-auditor.dto.js +17 -0
- package/src/domain/auditor/get-auditor.dto.js.map +1 -0
- package/src/domain/campaign/CampaignsEntitiesConfig.dto.d.ts +7 -0
- package/src/domain/campaign/CampaignsEntitiesConfig.dto.js +10 -0
- package/src/domain/campaign/CampaignsEntitiesConfig.dto.js.map +1 -0
- package/src/private-campaign-management-api.client.d.ts +18 -0
- package/src/private-campaign-management-api.client.js +79 -0
- package/src/private-campaign-management-api.client.js.map +1 -0
- package/.vscode/launch.json +0 -36
- package/.vscode/settings.json +0 -4
- package/.vscode/tasks.json +0 -41
- package/README.md +0 -2
- package/jest.config.single-file.json +0 -20
- package/jest.config.unit.json +0 -19
- package/src/auditor-campaign-management-api.client.ts +0 -54
- package/src/campaign-management-api.client.ts +0 -68
- package/src/domain/auditor/campaigns/geotargeting.entities.ts +0 -20
- package/src/domain/auditor/enums/auditor-entity-type.enum.ts +0 -3
- package/src/domain/auditor/get-auditor.dto.ts +0 -33
- package/src/domain/campaign/CampaignsEntitiesConfig.dto.ts +0 -7
- package/src/private-campaign-management-api.client.ts +0 -80
- package/tests-u/domain/auditor/auditor-campaign-management-api-client.test.ts +0 -99
- package/tests-u/domain/auditor/enums/auditor-entity-type-enum.test.ts +0 -22
- package/tests-u/domain/auditor/enums/auditor-operation-enum.test.ts +0 -34
- package/tests-u/domain/auditor/get-auditor-entity.test.ts +0 -34
- package/tests-u/domain/campaign/campaign-management-api-client.test.ts +0 -111
- package/tests-u/domain/campaign/private-campaign-management-api-client.test.ts +0 -114
- package/tsconfig.json +0 -39
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
import { SuperAgentRequest } from "superagent";
|
|
4
|
-
import { GetAuditorDto } from "./domain/auditor/get-auditor.dto";
|
|
5
|
-
import { AuditorOperation } from "./domain/auditor/enums/auditor-operation.enum";
|
|
6
|
-
import { injectable } from "inversify";
|
|
7
|
-
|
|
8
|
-
import * as superagent from "superagent";
|
|
9
|
-
|
|
10
|
-
@injectable()
|
|
11
|
-
export class AuditorCampaignManagementAPIClient {
|
|
12
|
-
public constructor(
|
|
13
|
-
private readonly baseUrl: string
|
|
14
|
-
) { }
|
|
15
|
-
|
|
16
|
-
public async getCampaignAuditorData(campaignID: number, jwt = ""): Promise<GetAuditorDto[]> {
|
|
17
|
-
const result = await this.getRequest(`auditor/campaigns/${campaignID}`, jwt);
|
|
18
|
-
const getAuditorDtos = result.body as GetAuditorDto[];
|
|
19
|
-
|
|
20
|
-
return getAuditorDtos;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async storeCampaignAuditorData(operation: AuditorOperation, campaignID: number, username: string, isUserAction: boolean, data: any, jwt = ""): Promise<GetAuditorDto> {
|
|
24
|
-
const sendData = {
|
|
25
|
-
"operation": operation,
|
|
26
|
-
"entityID": campaignID,
|
|
27
|
-
"username": username,
|
|
28
|
-
"isUserAction": isUserAction,
|
|
29
|
-
"data": data
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const result = await this.postRequest(`auditor/campaigns`, sendData, jwt);
|
|
33
|
-
|
|
34
|
-
return result.body as GetAuditorDto;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
private async getRequest(relative: string = "", jwt = ""): Promise<SuperAgentRequest> {
|
|
39
|
-
return await superagent.get(this.buildBaseUrl(relative))
|
|
40
|
-
.set("Content-Type", "application/json")
|
|
41
|
-
.set("Authorization", jwt);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private async postRequest(relative: string = "", data: any, jwt = ""): Promise<SuperAgentRequest> {
|
|
45
|
-
return await superagent.post(this.buildBaseUrl(relative))
|
|
46
|
-
.set("Content-Type", "application/json")
|
|
47
|
-
.set("Authorization", jwt)
|
|
48
|
-
.send(data);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private buildBaseUrl(relative: string): string {
|
|
52
|
-
return `${this.baseUrl}/${relative}`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
import { SuperAgentRequest } from "superagent";
|
|
4
|
-
import { injectable } from "inversify";
|
|
5
|
-
import { CampaignsEntitiesConfigDto } from "./domain/campaign/CampaignsEntitiesConfig.dto";
|
|
6
|
-
|
|
7
|
-
import * as superagent from "superagent";
|
|
8
|
-
|
|
9
|
-
@injectable()
|
|
10
|
-
export class CampaignManagementAPIClient {
|
|
11
|
-
public constructor(
|
|
12
|
-
private readonly baseUrl: string
|
|
13
|
-
) { }
|
|
14
|
-
|
|
15
|
-
public async addCampaignsEntitiesConfigs(campaignID: number, campaignsEntitiesConfigs: CampaignsEntitiesConfigDto[]): Promise<any> {
|
|
16
|
-
const path = `campaigns/add-campaigns-entities-configs`;
|
|
17
|
-
const data = {
|
|
18
|
-
campaignsEntitiesConfigs: campaignsEntitiesConfigs,
|
|
19
|
-
campaignID: campaignID
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return await this.postRequest(path, data);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public async removeCampaignsEntitiesConfigsByID(campaignID: number, campaignsEntitiesConfigsIDs: number[]): Promise<any> {
|
|
26
|
-
const path = `campaigns/remove-campaigns-entities-configs`;
|
|
27
|
-
const data = { campaignsEntitiesConfigsIDs: campaignsEntitiesConfigsIDs, campaignID: campaignID };
|
|
28
|
-
|
|
29
|
-
return await this.postRequest(path, data);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public async clearCampaignsEntitiesConfigsByCampaignID(campaignID: number): Promise<any> {
|
|
33
|
-
const path = `campaigns/clear-campaigns-entities-configs`;
|
|
34
|
-
const data = { campaignID: campaignID };
|
|
35
|
-
|
|
36
|
-
return await this.postRequest(path, data);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public async setEntitiesBasic(campaignID: number, organisationIDs: number[], studyIDs: number[]): Promise<any> {
|
|
40
|
-
const path = `campaigns/set-entities-basic`;
|
|
41
|
-
const data = {
|
|
42
|
-
organisationIDs: organisationIDs,
|
|
43
|
-
studyIDs: studyIDs,
|
|
44
|
-
campaignID: campaignID
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return await this.postRequest(path, data);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async setEntitiesPremium(campaignID: number, organisationIDs: number[], studyIDs: number[]): Promise<any> {
|
|
51
|
-
const path = `campaigns/set-entities-premium`;
|
|
52
|
-
const data = {
|
|
53
|
-
organisationIDs: organisationIDs,
|
|
54
|
-
studyIDs: studyIDs,
|
|
55
|
-
campaignID: campaignID
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return await this.postRequest(path, data);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private async postRequest(relative: string = "", data: any): Promise<SuperAgentRequest> {
|
|
62
|
-
return await superagent.post(this.buildBaseUrl(relative)).set("Content-Type", "application/json").send(data);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private buildBaseUrl(relative: string): string {
|
|
66
|
-
return `${this.baseUrl}/${relative}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
interface NumberMap { [key: string]: number; }
|
|
2
|
-
|
|
3
|
-
interface ICampaignAuditorData {
|
|
4
|
-
geo: any[];
|
|
5
|
-
pricing: Pricing;
|
|
6
|
-
geo_remainders: NumberMap;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class Pricing {
|
|
10
|
-
public constructor(
|
|
11
|
-
public s: NumberMap = {},
|
|
12
|
-
public o: NumberMap = {}
|
|
13
|
-
) {}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export {
|
|
17
|
-
ICampaignAuditorData,
|
|
18
|
-
NumberMap,
|
|
19
|
-
Pricing
|
|
20
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { AuditorEntityType } from "./enums/auditor-entity-type.enum";
|
|
2
|
-
import { AuditorOperation } from "./enums/auditor-operation.enum";
|
|
3
|
-
|
|
4
|
-
export class GetAuditorDto {
|
|
5
|
-
public readonly id: number;
|
|
6
|
-
public readonly auditTime: string
|
|
7
|
-
public readonly operation: AuditorOperation
|
|
8
|
-
public readonly entityID: number
|
|
9
|
-
public readonly entityType: AuditorEntityType
|
|
10
|
-
public readonly username: string
|
|
11
|
-
public readonly isUserAction: boolean
|
|
12
|
-
public readonly data: any
|
|
13
|
-
|
|
14
|
-
public constructor(
|
|
15
|
-
id: number,
|
|
16
|
-
auditTime: string,
|
|
17
|
-
operation: AuditorOperation,
|
|
18
|
-
entityID: number,
|
|
19
|
-
entityType: AuditorEntityType,
|
|
20
|
-
username: string,
|
|
21
|
-
isUserAction: boolean,
|
|
22
|
-
data: any
|
|
23
|
-
) {
|
|
24
|
-
this.id = id;
|
|
25
|
-
this.auditTime = auditTime;
|
|
26
|
-
this.operation = operation;
|
|
27
|
-
this.entityID = entityID;
|
|
28
|
-
this.entityType = entityType;
|
|
29
|
-
this.username = username;
|
|
30
|
-
this.isUserAction = isUserAction;
|
|
31
|
-
this.data = data;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import "reflect-metadata";
|
|
2
|
-
|
|
3
|
-
import { SuperAgentRequest } from "superagent";
|
|
4
|
-
import { injectable } from "inversify";
|
|
5
|
-
import { CampaignsEntitiesConfigDto } from "./domain/campaign/CampaignsEntitiesConfig.dto";
|
|
6
|
-
import { ISuperAgentRequestFactory, SignedRequestSender } from "@studyportals/mb-platform-http-requests";
|
|
7
|
-
|
|
8
|
-
@injectable()
|
|
9
|
-
export class PrivateCampaignManagementAPIClient {
|
|
10
|
-
public constructor(
|
|
11
|
-
private readonly superAgentRequestFactory: ISuperAgentRequestFactory,
|
|
12
|
-
private readonly requestSender: SignedRequestSender,
|
|
13
|
-
private readonly baseUrl: string
|
|
14
|
-
) { }
|
|
15
|
-
|
|
16
|
-
public async addCampaignsEntitiesConfigs(campaignID: number, campaignsEntitiesConfigs: CampaignsEntitiesConfigDto[]): Promise<any> {
|
|
17
|
-
const path = `private/campaigns/add-campaigns-entities-configs`;
|
|
18
|
-
const data = {
|
|
19
|
-
campaignsEntitiesConfigs: campaignsEntitiesConfigs,
|
|
20
|
-
campaignID: campaignID
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return await this.postRequest(path, data);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public async removeCampaignsEntitiesConfigsByID(campaignID: number, campaignsEntitiesConfigsIDs: number[]): Promise<any> {
|
|
27
|
-
const path = `private/campaigns/remove-campaigns-entities-configs`;
|
|
28
|
-
const data = { campaignsEntitiesConfigsIDs: campaignsEntitiesConfigsIDs, campaignID: campaignID };
|
|
29
|
-
|
|
30
|
-
return await this.postRequest(path, data);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async clearCampaignsEntitiesConfigsByCampaignID(campaignID: number): Promise<any> {
|
|
34
|
-
const path = `private/campaigns/clear-campaigns-entities-configs`;
|
|
35
|
-
const data = { campaignID: campaignID };
|
|
36
|
-
|
|
37
|
-
return await this.postRequest(path, data);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async setEntitiesBasic(campaignID: number, organisationIDs: number[], studyIDs: number[]): Promise<any> {
|
|
41
|
-
const path = `private/campaigns/set-entities-basic`;
|
|
42
|
-
const data = {
|
|
43
|
-
organisationIDs: organisationIDs,
|
|
44
|
-
studyIDs: studyIDs,
|
|
45
|
-
campaignID: campaignID
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return await this.postRequest(path, data);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async setEntitiesPremium(campaignID: number, organisationIDs: number[], studyIDs: number[]): Promise<any> {
|
|
52
|
-
const path = `private/campaigns/set-entities-premium`;
|
|
53
|
-
const data = {
|
|
54
|
-
organisationIDs: organisationIDs,
|
|
55
|
-
studyIDs: studyIDs,
|
|
56
|
-
campaignID: campaignID
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return await this.postRequest(path, data);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private async postRequest(relative: string = "", data: any): Promise<any> {
|
|
63
|
-
const request = this.createPostRequest(relative);
|
|
64
|
-
return await this.sendRequest(request, data);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private createPostRequest(relative: string = ""): SuperAgentRequest {
|
|
68
|
-
const url = this.buildBaseUrl(relative);
|
|
69
|
-
return this.superAgentRequestFactory.post(url);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private async sendRequest(request: SuperAgentRequest, payload: any): Promise<any> {
|
|
73
|
-
request.send(payload);
|
|
74
|
-
return await this.requestSender.send(request);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private buildBaseUrl(relative: string): string {
|
|
78
|
-
return `${this.baseUrl}/${relative}`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { suite, test } from "@testdeck/jest";
|
|
2
|
-
import { MockProxy, mock } from "jest-mock-extended";
|
|
3
|
-
import { assert } from "chai";
|
|
4
|
-
import { AuditorCampaignManagementAPIClient } from "../../../src/auditor-campaign-management-api.client";
|
|
5
|
-
import { IRequestSender, ISuperAgentRequestFactory, RequestSender } from "@studyportals/mb-platform-http-requests";
|
|
6
|
-
import { SuperAgentRequest } from "superagent";
|
|
7
|
-
import { AuditorOperation } from "../../../src/domain/auditor/enums/auditor-operation.enum";
|
|
8
|
-
import * as superagent from "superagent";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const superagentMock = require("superagent-mocker")(superagent);
|
|
12
|
-
|
|
13
|
-
@suite
|
|
14
|
-
class AuditorCampaignManagementAPIClientTest {
|
|
15
|
-
private auditorCampaignManagementAPIClient: AuditorCampaignManagementAPIClient;
|
|
16
|
-
private mockedRequestSender: MockProxy<IRequestSender> = mock<IRequestSender>();
|
|
17
|
-
private mockedRequest: MockProxy<SuperAgentRequest> = mock<SuperAgentRequest>();
|
|
18
|
-
private mockedSuperAgentRequestFactory: MockProxy<ISuperAgentRequestFactory> = mock<ISuperAgentRequestFactory>();
|
|
19
|
-
private mockedBaseUrl = "SomeBaseUrl";
|
|
20
|
-
|
|
21
|
-
public before() {
|
|
22
|
-
this.mockedSuperAgentRequestFactory.get.mockReturnValue(this.mockedRequest);
|
|
23
|
-
this.mockedSuperAgentRequestFactory.post.mockReturnValue(this.mockedRequest);
|
|
24
|
-
|
|
25
|
-
this.auditorCampaignManagementAPIClient = new AuditorCampaignManagementAPIClient(this.mockedBaseUrl);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@test()
|
|
29
|
-
public async getCampaignAuditorData__CorrectlyCalled() {
|
|
30
|
-
const receivedAuditorData = [
|
|
31
|
-
{
|
|
32
|
-
"id": 17428964,
|
|
33
|
-
"auditTime": "2023-00-00 13:55:09",
|
|
34
|
-
"operation": "update",
|
|
35
|
-
"entityID": 1,
|
|
36
|
-
"entityType": "campaign",
|
|
37
|
-
"username": "Jens Testing",
|
|
38
|
-
"isUserAction": true,
|
|
39
|
-
"data": "{\"geo\":[{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}}],\"pricing\":{\"s\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000},\"o\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000}},\"cpm\":{\"s\":{\"p\":1000,\"b\":2000},\"o\":{\"p\":1000,\"b\":2000}}}"
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"id": 17428967,
|
|
43
|
-
"auditTime": "2023-00-00 14:55:54",
|
|
44
|
-
"operation": "update",
|
|
45
|
-
"entityID": 1,
|
|
46
|
-
"entityType": "campaign",
|
|
47
|
-
"username": "Jens Testing",
|
|
48
|
-
"isUserAction": true,
|
|
49
|
-
"data": "{\"geo\":[{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}}],\"pricing\":{\"s\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000},\"o\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000}},\"cpm\":{\"s\":{\"p\":1000,\"b\":2000},\"o\":{\"p\":1000,\"b\":2000}}}"
|
|
50
|
-
}
|
|
51
|
-
];
|
|
52
|
-
this.mockedRequestSender.sendAndExtractBody.mockResolvedValue(receivedAuditorData);
|
|
53
|
-
|
|
54
|
-
const campaignID = 1;
|
|
55
|
-
superagentMock.get(`${this.mockedBaseUrl}/auditor/campaigns/${campaignID}`, () => {
|
|
56
|
-
return {
|
|
57
|
-
body: receivedAuditorData
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const result = await this.auditorCampaignManagementAPIClient.getCampaignAuditorData(campaignID);
|
|
62
|
-
|
|
63
|
-
assert.equal(result[0].id, receivedAuditorData[0].id);
|
|
64
|
-
assert.equal(result[1].id, receivedAuditorData[1].id);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
@test()
|
|
68
|
-
public async storeCampaignAuditorData__CorrectlyCalled() {
|
|
69
|
-
const sendData = {
|
|
70
|
-
"operation": "update",
|
|
71
|
-
"entityID": 1,
|
|
72
|
-
"username": "SomeName",
|
|
73
|
-
"isUserAction": true,
|
|
74
|
-
"data": {"some":"data"}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const id = 17428967;
|
|
78
|
-
const receivedData = {
|
|
79
|
-
"id": id,
|
|
80
|
-
"auditTime": "2023-00-00 14:55:54",
|
|
81
|
-
"operation": "update",
|
|
82
|
-
"entityID": 1,
|
|
83
|
-
"entityType": "campaign",
|
|
84
|
-
"username": "Jens Testing",
|
|
85
|
-
"isUserAction": true,
|
|
86
|
-
"data": "{\"geo\":[{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}},{\"s\":10000,\"o\":10000,\"c\":{\"sp\":1000,\"lp\":2000,\"p\":3000,\"b\":4000}}],\"pricing\":{\"s\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000},\"o\":{\"100\":1000,\"200\":2000,\"300\":3000,\"400\":3000,\"500\":3000}},\"cpm\":{\"s\":{\"p\":1000,\"b\":2000},\"o\":{\"p\":1000,\"b\":2000}}}"
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
superagentMock.post(`${this.mockedBaseUrl}/auditor/campaigns`, () => {
|
|
90
|
-
return {
|
|
91
|
-
body: receivedData
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const result = await this.auditorCampaignManagementAPIClient.storeCampaignAuditorData(AuditorOperation.UPDATE, sendData.entityID, sendData.username, sendData.isUserAction, sendData.data);
|
|
96
|
-
|
|
97
|
-
assert.equal(result.id, id);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { suite, test } from "@testdeck/jest";
|
|
2
|
-
import { assert } from "chai";
|
|
3
|
-
import { AuditorEntityType } from "../../../../src/domain/auditor/enums/auditor-entity-type.enum";
|
|
4
|
-
|
|
5
|
-
@suite
|
|
6
|
-
class AuditorEntityTypeEnumTest {
|
|
7
|
-
@test()
|
|
8
|
-
public hasEnumValues_ExpectedValues_Successful() {
|
|
9
|
-
const auditorEntityKeys = this.getAllEntityKeys();
|
|
10
|
-
|
|
11
|
-
assert.isTrue(auditorEntityKeys.length === 1);
|
|
12
|
-
|
|
13
|
-
assert.isTrue(AuditorEntityType.CAMPAIGN === "campaign");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
private getAllEntityKeys(): string[] {
|
|
18
|
-
return [
|
|
19
|
-
"CAMPAIGN"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { suite, test } from "@testdeck/jest";
|
|
2
|
-
import { assert } from "chai";
|
|
3
|
-
import { AuditorOperation } from "../../../../src/domain/auditor/enums/auditor-operation.enum";
|
|
4
|
-
|
|
5
|
-
@suite
|
|
6
|
-
class AuditorOperationEnumTest {
|
|
7
|
-
@test()
|
|
8
|
-
public hasEnumValues_ExpectedValues_Successful() {
|
|
9
|
-
const auditorEntityKeys = this.getAllEntityKeys();
|
|
10
|
-
|
|
11
|
-
assert.isTrue(auditorEntityKeys.length === 7);
|
|
12
|
-
|
|
13
|
-
assert.isTrue(AuditorOperation.CLEANUP === "cleanup");
|
|
14
|
-
assert.isTrue(AuditorOperation.UPDATE === "update");
|
|
15
|
-
assert.isTrue(AuditorOperation.CREATE === "create");
|
|
16
|
-
assert.isTrue(AuditorOperation.LINK === "link");
|
|
17
|
-
assert.isTrue(AuditorOperation.UNLINK === "unlink");
|
|
18
|
-
assert.isTrue(AuditorOperation.DELETE === "delete");
|
|
19
|
-
assert.isTrue(AuditorOperation.ENDOR === "endor");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
private getAllEntityKeys(): string[] {
|
|
24
|
-
return [
|
|
25
|
-
"CLEANUP",
|
|
26
|
-
"UPDATE",
|
|
27
|
-
"CREATE",
|
|
28
|
-
"LINK",
|
|
29
|
-
"UNLINK",
|
|
30
|
-
"DELETE",
|
|
31
|
-
"ENDOR"
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { UTCDateTime } from "@studyportals/mb-platform-date-time";
|
|
2
|
-
import { suite, test } from "@testdeck/jest";
|
|
3
|
-
import { assert } from "chai";
|
|
4
|
-
import { AuditorEntityType } from "../../../src/domain/auditor/enums/auditor-entity-type.enum";
|
|
5
|
-
import { AuditorOperation } from "../../../src/domain/auditor/enums/auditor-operation.enum";
|
|
6
|
-
import { GetAuditorDto } from "../../../src/domain/auditor/get-auditor.dto";
|
|
7
|
-
|
|
8
|
-
@suite
|
|
9
|
-
class GetAuditorEntityTest {
|
|
10
|
-
@test()
|
|
11
|
-
public hasEnumValues_ExpectedValues_Successful() {
|
|
12
|
-
const id = 1;
|
|
13
|
-
const auditTime = UTCDateTime.now().toString();
|
|
14
|
-
const operation = AuditorOperation.CREATE;
|
|
15
|
-
const entityID = 2;
|
|
16
|
-
const entityType = AuditorEntityType.CAMPAIGN;
|
|
17
|
-
const username = "SomeUser";
|
|
18
|
-
const isUserAction = true;
|
|
19
|
-
const data = {
|
|
20
|
-
"SomeDataKey": "SomeDataValue"
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const getAuditorEntity = new GetAuditorDto(id, auditTime, operation, entityID, entityType, username, isUserAction, data);
|
|
24
|
-
|
|
25
|
-
assert.equal(getAuditorEntity.id, id);
|
|
26
|
-
assert.equal(getAuditorEntity.auditTime, auditTime);
|
|
27
|
-
assert.equal(getAuditorEntity.operation, operation);
|
|
28
|
-
assert.equal(getAuditorEntity.entityID, entityID);
|
|
29
|
-
assert.equal(getAuditorEntity.entityType, entityType);
|
|
30
|
-
assert.equal(getAuditorEntity.username, username);
|
|
31
|
-
assert.equal(getAuditorEntity.isUserAction, isUserAction);
|
|
32
|
-
assert.equal(getAuditorEntity.data, data);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { suite, test } from "@testdeck/jest";
|
|
2
|
-
import { MockProxy, mock } from "jest-mock-extended";
|
|
3
|
-
import { assert } from "chai";
|
|
4
|
-
import { ISuperAgentRequestFactory } from "@studyportals/mb-platform-http-requests";
|
|
5
|
-
import { SuperAgentRequest } from "superagent";
|
|
6
|
-
import * as superagent from "superagent";
|
|
7
|
-
import { CampaignManagementAPIClient } from "../../../src/campaign-management-api.client";
|
|
8
|
-
import { CampaignsEntitiesConfigDto } from "../../../src/domain/campaign/CampaignsEntitiesConfig.dto";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const superagentMock = require("superagent-mocker")(superagent);
|
|
12
|
-
|
|
13
|
-
@suite
|
|
14
|
-
class CampaignManagementAPIClientTest {
|
|
15
|
-
private campaignManagementAPIClient: CampaignManagementAPIClient;
|
|
16
|
-
private mockedRequest: MockProxy<SuperAgentRequest> = mock<SuperAgentRequest>();
|
|
17
|
-
private mockedSuperAgentRequestFactory: MockProxy<ISuperAgentRequestFactory> = mock<ISuperAgentRequestFactory>();
|
|
18
|
-
private mockedBaseUrl = "SomeBaseUrl";
|
|
19
|
-
|
|
20
|
-
public before() {
|
|
21
|
-
this.mockedSuperAgentRequestFactory.post.mockReturnValue(this.mockedRequest);
|
|
22
|
-
|
|
23
|
-
this.campaignManagementAPIClient = new CampaignManagementAPIClient(this.mockedBaseUrl);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@test()
|
|
27
|
-
public async addCampaignsEntitiesConfigs__CorrectlyCalled() {
|
|
28
|
-
const postData: CampaignsEntitiesConfigDto = {
|
|
29
|
-
campaign_id: 1,
|
|
30
|
-
sp_id: 1,
|
|
31
|
-
product_id: 12,
|
|
32
|
-
product2_id: null,
|
|
33
|
-
type: "study"
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
superagentMock.post(`${this.mockedBaseUrl}/campaigns/add-campaigns-entities-configs`, () => {});
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const result = await this.campaignManagementAPIClient.addCampaignsEntitiesConfigs(1, [postData]);
|
|
40
|
-
} catch {
|
|
41
|
-
assert.fail();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
assert.ok(true);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@test()
|
|
48
|
-
public async removeCampaignsEntitiesConfigsByID__CorrectlyCalled() {
|
|
49
|
-
const campaignID = 1;
|
|
50
|
-
const entityIDs = [ 1 ];
|
|
51
|
-
|
|
52
|
-
superagentMock.post(`${this.mockedBaseUrl}/campaigns/remove-campaigns-entities-configs`, () => {});
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const result = await this.campaignManagementAPIClient.removeCampaignsEntitiesConfigsByID(campaignID, entityIDs);
|
|
56
|
-
} catch {
|
|
57
|
-
assert.fail();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
assert.ok(true);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@test()
|
|
64
|
-
public async clearCampaignsEntitiesConfigsByCampaignID__CorrectlyCalled() {
|
|
65
|
-
const postData = 1;
|
|
66
|
-
|
|
67
|
-
superagentMock.post(`${this.mockedBaseUrl}/campaigns/clear-campaigns-entities-configs`, () => {});
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const result = await this.campaignManagementAPIClient.clearCampaignsEntitiesConfigsByCampaignID(postData);
|
|
71
|
-
} catch {
|
|
72
|
-
assert.fail();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
assert.ok(true);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@test()
|
|
79
|
-
public async setEntitiesBasic__CorrectlyCalled() {
|
|
80
|
-
const campaignID = 1;
|
|
81
|
-
const organisationIDs = [1];
|
|
82
|
-
const studyIDs = [5];
|
|
83
|
-
|
|
84
|
-
superagentMock.post(`${this.mockedBaseUrl}/campaigns/set-entities-basic`, () => {});
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const result = await this.campaignManagementAPIClient.setEntitiesBasic(campaignID, organisationIDs, studyIDs);
|
|
88
|
-
} catch {
|
|
89
|
-
assert.fail();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
assert.ok(true);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@test()
|
|
96
|
-
public async setEntitiesPremium__CorrectlyCalled() {
|
|
97
|
-
const campaignID = 1;
|
|
98
|
-
const organisationIDs = [1];
|
|
99
|
-
const studyIDs = [5];
|
|
100
|
-
|
|
101
|
-
superagentMock.post(`${this.mockedBaseUrl}/campaigns/set-entities-premium`, () => {});
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const result = await this.campaignManagementAPIClient.setEntitiesPremium(campaignID, organisationIDs, studyIDs);
|
|
105
|
-
} catch {
|
|
106
|
-
assert.fail();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
assert.ok(true);
|
|
110
|
-
}
|
|
111
|
-
}
|