Skip to content

Commit

Permalink
Merge branch 'main' into feat/esm-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
kayluhb authored May 24, 2024
2 parents 08f43f7 + 993874a commit 672f84f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [2.14.0](https://github.com/algolia/search-insights.js/compare/v2.13.0...v2.14.0) (2024-05-22)


### Features

* fast fail when sending no events ([#532](https://github.com/algolia/search-insights.js/issues/532)) ([de26c37](https://github.com/algolia/search-insights.js/commit/de26c37732d59cf2a2ec78768fed005e64dfc4c9))



# [2.13.0](https://github.com/algolia/search-insights.js/compare/v2.12.0...v2.13.0) (2023-12-11)


Expand Down
8 changes: 8 additions & 0 deletions lib/__tests__/_sendEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,14 @@ describe("sendEvents", () => {
}
);
});

it("should fail fast when sending no events via sendEvents", async () => {
const result = analyticsInstance.sendEvents([]);

expect(result).toBeInstanceOf(Promise);
expect(await result).toBe(false);
expect(fakeRequestFn).toHaveBeenCalledTimes(0);
});
});

it("applies default credentials when no custom ones are provided", () => {
Expand Down
4 changes: 4 additions & 0 deletions lib/_sendEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function makeSendEvents(requestFn: RequestFnType) {
return payload;
});

if (events.length === 0) {
return Promise.resolve(false);
}

return sendRequest(
requestFn,
this._ua,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "search-insights",
"description": "Library for reporting click, conversion and view metrics using the Algolia Insights API",
"version": "2.13.0",
"version": "2.14.0",
"jsdelivr": "dist/search-insights.min.js",
"main": "index-node.cjs.js",
"types": "index-node.cjs.d.ts",
Expand Down

0 comments on commit 672f84f

Please sign in to comment.