Skip to content

Commit

Permalink
fix error that occurs when querying older Matomos without metricTypes…
Browse files Browse the repository at this point in the history
… metadata (#73)

* fix error that occurs when querying older Matomos without metricTypes metadata

* log current test name when running apps script function during tests

* tweak log message

* debug test failure

* remove .only() in test

* add wait after creating the local tunnel target server in tests
  • Loading branch information
diosmosis authored Sep 17, 2024
1 parent 08ee4c1 commit cb06a15
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src-test/callFunctionInTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

export function callFunctionInTest(functionName: string, ...params: unknown[]) {
export function callFunctionInTest(functionName: string, testName: string, ...params: unknown[]) {
try {
console.log(`calling ${functionName} in test "${testName}"`);

// there is no global object (like window) in apps script, so this is how we get a global function by name
const fn = eval(functionName);
const result = fn(...params);
Expand Down
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export function fetchAll(requests: MatomoRequestParams[], options: ApiFetchOptio

if (errorResponses.length === 1) {
const { method, params } = requests[errorResponses[0].index];
throwUnexpectedError(new Error(`API method ${method} failed with: "${errorResponses[0].message}". (params = ${JSON.stringify(params)})`), 'api client');
throwUnexpectedError(new Error(`API method ${method} failed (params = ${JSON.stringify(params)}): "${errorResponses[0].message}".`), 'api client');
} else if (errorResponses.length > 1) {
throwUnexpectedError(new Error(`${errorResponses.length} API methods failed.`), 'api client');
}
Expand Down
2 changes: 2 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ function getFieldsFromReportMetadata(reportMetadata: Api.ReportMetadata, goals:
allMetrics = { ...allMetrics, ...metricsForEachGoal({ 'conversion_rate': 'Conversion Rate' }, goals) };
}

reportMetadata.metricTypes = reportMetadata.metricTypes || {};

// pre 5.1.0, the overall conversions and revenue sum metrics were not present in metadata output,
// but the data exists in the actual API output
if (reportMetadata.module !== 'Actions') {
Expand Down
2 changes: 2 additions & 0 deletions tests/appscript/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ describe('api', () => {
},
});

await new Promise((resolve) => setTimeout(resolve, 5000));

// use the mock server's path that forces a random error
const result = await Clasp.run('setCredentials', {
userToken: {
Expand Down
3 changes: 2 additions & 1 deletion tests/utilities/clasp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class Clasp {
}

async run(functionName: string, ...args: any[]) {
return this.runExecutable(['run', '-p', JSON.stringify([functionName, ...args]), 'callFunctionInTest']);
const testName = expect.getState().currentTestName;
return this.runExecutable(['run', '-p', JSON.stringify([functionName, testName, ...args]), 'callFunctionInTest']);
}

async setScriptProperties(properties: Record<string, string>, deleteExisting = false) {
Expand Down

0 comments on commit cb06a15

Please sign in to comment.