From 94951f32b087ad2c35685dc2dee3217f6b8b2365 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:05:24 +0530 Subject: [PATCH 1/6] feat: add method to record ai asession analytics --- src/index.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/index.js b/src/index.js index 77ab1fd..d85c5d9 100644 --- a/src/index.js +++ b/src/index.js @@ -116,6 +116,13 @@ type ConversionRequestBody = { meta?: Object }; +type UsefulnessConfig = { + useful: boolean, + reason?: string, + userID?: string, + meta?: Object +}; + type CallBack = (err: any, res: any) => void; type Metrics = { @@ -149,6 +156,12 @@ type Metrics = { body?: Object, queryParams?: Object, callback?: CallBack + ) => void, + // Save session's usefulness + saveSessionUsefulness?: ( + aiSessionId: string, + usefulnessConfig: UsefulnessConfig, + callback?: CallBack ) => void }; @@ -394,6 +407,42 @@ function initClient(config: AnalyticsConfig = {}) { // get queryID metrics.getQueryID = () => metrics.queryID; + // Save session's usefulness + metrics.saveSessionUsefulness = ( + aiSessionId: string, + usefulnessConfig: { + useful: boolean, + reason?: string, + userID?: string, + meta?: Object + }, + callback?: CallBack + ) => { + if (typeof aiSessionId !== 'string' || aiSessionId === '') { + throw new Error('appbase-analytics: AISessionId is required'); + } + if (typeof usefulnessConfig.useful !== 'boolean') { + throw new Error( + 'appbase-analytics: useful property is required and must be a boolean' + ); + } + + const requestBody = { + useful: usefulnessConfig.useful, + reason: usefulnessConfig.reason, + user_id: usefulnessConfig.userID, + meta: usefulnessConfig.meta + }; + + metrics._request( + 'PUT', + `_ai/${aiSessionId}/analytics`, + requestBody, + null, + callback + ); + }; + return metrics; } From 5ad24d07f41750232f7f0a7c79e6c8fbc57de085 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:05:41 +0530 Subject: [PATCH 2/6] feat: add test case markup --- src/index.test.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/index.test.js b/src/index.test.js index 01d5893..5145c03 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -341,3 +341,35 @@ describe('favorite', () => { ); }); }); + +describe('saveSessionUsefulness', () => { + test("should save session's usefulness", done => { + var aa = AppbaseAnalytics.init({ + index, + credentials, + url: URL + }); + // Save session usefulness + aa.saveSessionUsefulness( + 'AISessionId', + { + useful: true, + reason: 'The AI provided accurate information.', + userID: 'john_doe', + meta: { + platform: 'windows' + } + }, + (err, res) => { + if (err) { + console.error(err); + expect(true).toBe(false); + done(); + } else if (res && res.status === 200) { + expect(true).toBe(true); + done(); + } + } + ); + }); +}); From 5d9bba878e9077c7c121b4b210077e753ca6f365 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Fri, 14 Apr 2023 12:14:25 +0530 Subject: [PATCH 3/6] improve test case and increase timeout --- jest.config.js | 3 ++- src/index.test.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/jest.config.js b/jest.config.js index 3dae129..3de4da0 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,4 @@ module.exports = { - verbose: true + verbose: true, + testTimeout: 30000 // Set the timeout to 10 seconds }; diff --git a/src/index.test.js b/src/index.test.js index 5145c03..b72ca72 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -341,7 +341,6 @@ describe('favorite', () => { ); }); }); - describe('saveSessionUsefulness', () => { test("should save session's usefulness", done => { var aa = AppbaseAnalytics.init({ @@ -351,7 +350,7 @@ describe('saveSessionUsefulness', () => { }); // Save session usefulness aa.saveSessionUsefulness( - 'AISessionId', + 'nt3f6nuE7QHoEWB6JCX5Z6', { useful: true, reason: 'The AI provided accurate information.', @@ -365,6 +364,10 @@ describe('saveSessionUsefulness', () => { console.error(err); expect(true).toBe(false); done(); + } else if (res && res.status === 401) { + console.error('401: Credentials no allowed to access AI'); + expect(false).toBe(true); + done(); } else if (res && res.status === 200) { expect(true).toBe(true); done(); From ba4cf64d8d48830333499c595f00066aca0f79b4 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Fri, 14 Apr 2023 12:14:44 +0530 Subject: [PATCH 4/6] remove extended timeout limit --- jest.config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jest.config.js b/jest.config.js index 3de4da0..3dae129 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,3 @@ module.exports = { - verbose: true, - testTimeout: 30000 // Set the timeout to 10 seconds + verbose: true }; From 9d176adae39d70657941f53cb11ff07b379730fd Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:33:35 +0530 Subject: [PATCH 5/6] add note to update credentials or sessionId --- src/index.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.test.js b/src/index.test.js index b72ca72..ecdd558 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -343,9 +343,11 @@ describe('favorite', () => { }); describe('saveSessionUsefulness', () => { test("should save session's usefulness", done => { + // Note: Chagne credentials or sessionId incase + // the test case fails var aa = AppbaseAnalytics.init({ index, - credentials, + credentials: 'a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61', url: URL }); // Save session usefulness From 1b32c54f3d4fca5c7128989c9c73000f87c03b68 Mon Sep 17 00:00:00 2001 From: Mohd Ashraf <57627350+mohdashraf010897@users.noreply.github.com> Date: Mon, 17 Apr 2023 11:34:41 +0530 Subject: [PATCH 6/6] v1.2.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index efd97c8..2cbb3be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@appbaseio/analytics", - "version": "1.1.1", + "version": "1.2.0-alpha.1", "description": "Universal analytics library for appbase.io apps", "main": "dist/@appbaseio/analytics.cjs.js", "jsnext:main": "dist/@appbaseio/analytics.es.js",