Skip to content

Commit ce40ded

Browse files
Merge branch 'main' into MI-949
2 parents 8c8ff28 + 7372e63 commit ce40ded

File tree

13 files changed

+525
-518
lines changed

13 files changed

+525
-518
lines changed

__tests__/__snapshots__/submissions.ts.snap

Lines changed: 0 additions & 16 deletions
This file was deleted.

__tests__/schema/posts/boost.ts

Lines changed: 80 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,14 +3100,19 @@ describe('query boostEstimatedReachDaily', () => {
31003100
impressions: 100,
31013101
clicks: 5,
31023102
users: 50,
3103+
min_impressions: 45,
3104+
max_impressions: 55,
31033105
});
31043106

31053107
const res = await client.query(QUERY, {
31063108
variables: { ...params, budget: 2000, duration: 5 }, // Valid budget
31073109
});
31083110

31093111
expect(res.errors).toBeFalsy();
3110-
expect(res.data.boostEstimatedReachDaily).toBeDefined();
3112+
expect(res.data.boostEstimatedReachDaily).toEqual({
3113+
min: 45,
3114+
max: 55,
3115+
});
31113116

31123117
// Verify the HTTP call was made with correct budget conversion
31133118
expect(mockFetchParse).toHaveBeenCalledWith(
@@ -3157,14 +3162,19 @@ describe('query boostEstimatedReachDaily', () => {
31573162
impressions: 200,
31583163
clicks: 10,
31593164
users: 75,
3165+
min_impressions: 68,
3166+
max_impressions: 82,
31603167
});
31613168

31623169
const res = await client.query(QUERY, {
31633170
variables: { ...params, budget: 3000, duration: 15 }, // Valid duration
31643171
});
31653172

31663173
expect(res.errors).toBeFalsy();
3167-
expect(res.data.boostEstimatedReachDaily).toBeDefined();
3174+
expect(res.data.boostEstimatedReachDaily).toEqual({
3175+
min: 68,
3176+
max: 82,
3177+
});
31683178

31693179
// Verify the HTTP call includes both parameters correctly
31703180
expect(mockFetchParse).toHaveBeenCalledWith(
@@ -3195,6 +3205,8 @@ describe('query boostEstimatedReachDaily', () => {
31953205
impressions: 500,
31963206
clicks: 40,
31973207
users: 180,
3208+
min_impressions: 166,
3209+
max_impressions: 194,
31983210
});
31993211

32003212
const res = await client.query(QUERY, {
@@ -3203,8 +3215,8 @@ describe('query boostEstimatedReachDaily', () => {
32033215

32043216
expect(res.errors).toBeFalsy();
32053217
expect(res.data.boostEstimatedReachDaily).toEqual({
3206-
max: 194, // 180 + Math.floor(180 * 0.08) = 180 + 14 = 194
3207-
min: 166, // 180 - Math.floor(180 * 0.08) = 180 - 14 = 166
3218+
min: 166,
3219+
max: 194,
32083220
});
32093221

32103222
// Verify the HTTP call was made correctly with both parameters
@@ -3235,6 +3247,8 @@ describe('query boostEstimatedReachDaily', () => {
32353247
impressions: 50,
32363248
clicks: 3,
32373249
users: 25,
3250+
min_impressions: 23,
3251+
max_impressions: 27,
32383252
});
32393253

32403254
const res = await client.query(QUERY, {
@@ -3243,8 +3257,8 @@ describe('query boostEstimatedReachDaily', () => {
32433257

32443258
expect(res.errors).toBeFalsy();
32453259
expect(res.data.boostEstimatedReachDaily).toEqual({
3246-
max: 27, // 25 + Math.floor(25 * 0.08) = 25 + 2 = 27
3247-
min: 23, // 25 - Math.floor(25 * 0.08) = 25 - 2 = 23
3260+
min: 23,
3261+
max: 27,
32483262
});
32493263

32503264
// Verify the HTTP call was made with minimum budget
@@ -3275,6 +3289,8 @@ describe('query boostEstimatedReachDaily', () => {
32753289
impressions: 50000,
32763290
clicks: 2500,
32773291
users: 15000,
3292+
min_impressions: 13800,
3293+
max_impressions: 16200,
32783294
});
32793295

32803296
const res = await client.query(QUERY, {
@@ -3283,8 +3299,8 @@ describe('query boostEstimatedReachDaily', () => {
32833299

32843300
expect(res.errors).toBeFalsy();
32853301
expect(res.data.boostEstimatedReachDaily).toEqual({
3286-
max: 16200, // 15000 + Math.floor(15000 * 0.08) = 15000 + 1200 = 16200
3287-
min: 13800, // 15000 - Math.floor(15000 * 0.08) = 15000 - 1200 = 13800
3302+
min: 13800,
3303+
max: 16200,
32883304
});
32893305

32903306
// Verify the HTTP call was made with maximum budget
@@ -3315,6 +3331,8 @@ describe('query boostEstimatedReachDaily', () => {
33153331
impressions: 80,
33163332
clicks: 5,
33173333
users: 35,
3334+
min_impressions: 33,
3335+
max_impressions: 37,
33183336
});
33193337

33203338
const res = await client.query(QUERY, {
@@ -3323,8 +3341,8 @@ describe('query boostEstimatedReachDaily', () => {
33233341

33243342
expect(res.errors).toBeFalsy();
33253343
expect(res.data.boostEstimatedReachDaily).toEqual({
3326-
max: 37, // 35 + Math.floor(35 * 0.08) = 35 + 2 = 37
3327-
min: 33, // 35 - Math.floor(35 * 0.08) = 35 - 2 = 33
3344+
min: 33,
3345+
max: 37,
33283346
});
33293347

33303348
// Verify the HTTP call was made with minimum duration
@@ -3355,6 +3373,8 @@ describe('query boostEstimatedReachDaily', () => {
33553373
impressions: 1200,
33563374
clicks: 60,
33573375
users: 450,
3376+
min_impressions: 414,
3377+
max_impressions: 486,
33583378
});
33593379

33603380
const res = await client.query(QUERY, {
@@ -3363,8 +3383,8 @@ describe('query boostEstimatedReachDaily', () => {
33633383

33643384
expect(res.errors).toBeFalsy();
33653385
expect(res.data.boostEstimatedReachDaily).toEqual({
3366-
max: 486, // 450 + Math.floor(450 * 0.08) = 450 + 36 = 486
3367-
min: 414, // 450 - Math.floor(450 * 0.08) = 450 - 36 = 414
3386+
min: 414,
3387+
max: 486,
33683388
});
33693389

33703390
// Verify the HTTP call was made with maximum duration
@@ -3404,6 +3424,8 @@ describe('query boostEstimatedReachDaily', () => {
34043424
impressions: 150,
34053425
clicks: 10,
34063426
users: 65,
3427+
min_impressions: 60,
3428+
max_impressions: 70,
34073429
});
34083430

34093431
const res = await client.query(QUERY, {
@@ -3412,8 +3434,8 @@ describe('query boostEstimatedReachDaily', () => {
34123434

34133435
expect(res.errors).toBeFalsy();
34143436
expect(res.data.boostEstimatedReachDaily).toEqual({
3415-
max: 70, // 65 + Math.floor(65 * 0.08) = 65 + 5 = 70
3416-
min: 60, // 65 - Math.floor(65 * 0.08) = 65 - 5 = 60
3437+
min: 60,
3438+
max: 70,
34173439
});
34183440

34193441
// Verify the HTTP call was made with correct parameters
@@ -3434,4 +3456,48 @@ describe('query boostEstimatedReachDaily', () => {
34343456
},
34353457
);
34363458
});
3459+
3460+
it('should fall back to getAdjustedReach when min and max impressions are equal', async () => {
3461+
loggedUser = '1';
3462+
3463+
// Mock the HTTP response where min and max impressions are the same
3464+
const mockFetchParse = fetchParse as jest.Mock;
3465+
mockFetchParse.mockResolvedValue({
3466+
impressions: 200,
3467+
clicks: 15,
3468+
users: 100,
3469+
min_impressions: 75, // Same value
3470+
max_impressions: 75, // Same value
3471+
});
3472+
3473+
const res = await client.query(QUERY, {
3474+
variables: { ...params, budget: 4000, duration: 10 }, // 4000 cores = 40 USD, 10 days
3475+
});
3476+
3477+
expect(res.errors).toBeFalsy();
3478+
// When min_impressions === max_impressions, it should use getAdjustedReach(maxImpressions)
3479+
// getAdjustedReach applies ±8% calculation: 75 ± Math.floor(75 * 0.08) = 75 ± 6
3480+
expect(res.data.boostEstimatedReachDaily).toEqual({
3481+
min: 69, // 75 - Math.floor(75 * 0.08) = 75 - 6 = 69
3482+
max: 81, // 75 + Math.floor(75 * 0.08) = 75 + 6 = 81
3483+
});
3484+
3485+
// Verify the HTTP call was made with correct parameters
3486+
expect(mockFetchParse).toHaveBeenCalledWith(
3487+
`${process.env.SKADI_API_ORIGIN}/promote/post/reach`,
3488+
{
3489+
method: 'POST',
3490+
headers: {
3491+
'Content-Type': 'application/json',
3492+
},
3493+
body: JSON.stringify({
3494+
post_id: 'p1',
3495+
user_id: '1',
3496+
duration: 10 * ONE_DAY_IN_SECONDS,
3497+
budget: 40, // Converted from cores to USD (4000 cores = 40 USD)
3498+
}),
3499+
agent: expect.any(Function),
3500+
},
3501+
);
3502+
});
34373503
});

0 commit comments

Comments
 (0)