From 65a3dfe90adcd9028ad24613eeb49e0d98d2351a Mon Sep 17 00:00:00 2001 From: Miriam Mchome Date: Thu, 4 Dec 2025 12:59:18 +0100 Subject: [PATCH 1/2] fix: null trend --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3428804c1..ef5b0d414 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@adobe/helix-universal-logger": "3.0.28", "@adobe/spacecat-helix-content-sdk": "1.4.32", "@adobe/spacecat-shared-ahrefs-client": "1.10.3", - "@adobe/spacecat-shared-athena-client": "1.8.2", + "@adobe/spacecat-shared-athena-client": "1.8.3", "@adobe/spacecat-shared-brand-client": "1.1.34", "@adobe/spacecat-shared-data-access": "2.88.8", "@adobe/spacecat-shared-gpt-client": "1.6.14", @@ -948,9 +948,9 @@ } }, "node_modules/@adobe/spacecat-shared-athena-client": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-athena-client/-/spacecat-shared-athena-client-1.8.2.tgz", - "integrity": "sha512-4FNK8GlWtzY7LbufHY5vdeoPM6cRDgECWMEmBMKjoIF1upwhym4B5KQ7wwhV3XgAd4RyezDKk1xgcFMMEOUK7g==", + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-athena-client/-/spacecat-shared-athena-client-1.8.3.tgz", + "integrity": "sha512-k0RWU6HfdPT4CO/alzyecl4M9YlV1AxcVjXjaO/3l+jIx7GE8UWRABXaBgKKeSHqFLK9PMhcCnitLjoWv3Ji8g==", "license": "Apache-2.0", "dependencies": { "@adobe/spacecat-shared-utils": "1.81.1", diff --git a/package.json b/package.json index 4d547faf1..1c7e0b2b7 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "@adobe/helix-universal-logger": "3.0.28", "@adobe/spacecat-helix-content-sdk": "1.4.32", "@adobe/spacecat-shared-ahrefs-client": "1.10.3", - "@adobe/spacecat-shared-athena-client": "1.8.2", + "@adobe/spacecat-shared-athena-client": "1.8.3", "@adobe/spacecat-shared-brand-client": "1.1.34", "@adobe/spacecat-shared-data-access": "2.88.8", "@adobe/spacecat-shared-gpt-client": "1.6.14", From 8f98c8aca38c225b0e82fc6f2c360deebf837d85 Mon Sep 17 00:00:00 2001 From: Miriam Mchome Date: Fri, 5 Dec 2025 10:46:30 +0100 Subject: [PATCH 2/2] test showing issue --- test/controllers/paid/traffic.test.js | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/test/controllers/paid/traffic.test.js b/test/controllers/paid/traffic.test.js index cc61395d4..09e89e66a 100644 --- a/test/controllers/paid/traffic.test.js +++ b/test/controllers/paid/traffic.test.js @@ -246,6 +246,86 @@ describe('Paid TrafficController', async () => { expect(query).to.include('trf_type'); }); + it('getPaidTrafficTemporalSeries with MONTH parameter should use month logic not week logic', async () => { + // This test demonstrates the bug where week=0 causes incorrect temporal conditions + mockContext.data = { + year: 2025, + month: 11, // November + // week is undefined, which becomes 0 in validateTemporalParams + }; + mockAthenaQuery.resolves([ + { + trf_type: 'paid', + pageviews: 1000, + pct_pageviews: 0.5, + click_rate: 0.1, + engagement_rate: 0.2, + bounce_rate: 0.3, + p70_lcp: 2.5, + p70_cls: 0.1, + p70_inp: 200, + }, + ]); + const controller = TrafficController(mockContext, mockLog, mockEnv); + const res = await controller.getPaidTrafficTemporalSeries(); + expect(res.status).to.equal(200); + expect(mockAthenaQuery).to.have.been.calledOnce; + + // Verify the query uses MONTH logic, not WEEK logic + const athenaCall = mockAthenaQuery.getCall(0); + expect(athenaCall).to.exist; + const query = athenaCall.args[0]; + expect(query).to.be.a('string'); + + // The query should contain month conditions for November and previous months IN 2025 + expect(query).to.include('year=2025 AND month=11'); // Current month (November 2025) + expect(query).to.include('year=2025 AND month=10'); // Previous month (October 2025) + expect(query).to.include('year=2025 AND month=9'); // 2 months ago (September 2025) + expect(query).to.include('year=2025 AND month=8'); // 3 months ago (August 2025) + + // The query should NOT contain year=2024 (the bug behavior - wrong year!) + expect(query).to.not.include('year=2024'); + + // The query should NOT contain week conditions (the bug behavior - wrong dimension!) + expect(query).to.not.include('week=52'); + expect(query).to.not.include('week=51'); + expect(query).to.not.include('week=50'); + expect(query).to.not.include('week=49'); + }); + + it('getPaidTrafficByType with MONTH parameter should use month logic (non-temporal series)', async () => { + // Test the non-numSeries case (numSeries=1) to verify month logic works correctly + mockContext.data = { + year: 2025, + month: 11, // November + // week is undefined, which becomes 0 in validateTemporalParams + }; + mockAthenaQuery.resolves([ + { + trf_type: 'paid', + pageviews: 1000, + pct_pageviews: 0.5, + }, + ]); + const controller = TrafficController(mockContext, mockLog, mockEnv); + const res = await controller.getPaidTrafficByType(); + expect(res.status).to.equal(200); + expect(mockAthenaQuery).to.have.been.calledOnce; + + // Verify the query uses MONTH logic for single period + const athenaCall = mockAthenaQuery.getCall(0); + expect(athenaCall).to.exist; + const query = athenaCall.args[0]; + expect(query).to.be.a('string'); + + // Should contain the correct year and month + expect(query).to.include('year=2025'); + expect(query).to.include('month=11'); + + // Should NOT contain week conditions + expect(query).to.not.include('week='); + }); + it('does not log error if cache file is missing (known exception)', async () => { mockAthenaQuery.resolves(trafficTypeMock); const controller = TrafficController(mockContext, mockLog, mockEnv);