Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 13a2fa0

Browse files
authored
Merge pull request #55 from apisearch-io/feature/adding-click-to-repository
Added click method in repository
2 parents f327d51 + bc18ec2 commit 13a2fa0

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apisearch",
3-
"version": "0.2.24",
3+
"version": "0.2.25",
44
"description": "Javascript client for Apisearch.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/Repository/HttpRepository.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,36 @@ export class HttpRepository extends Repository {
342342
}
343343
}
344344

345+
/**
346+
* Click
347+
*
348+
* @param {Item} item
349+
* @param {string} user_id
350+
*
351+
* @return {Promise<void>}
352+
*/
353+
public async click(
354+
item: Item,
355+
user_id?: string
356+
): Promise<void> {
357+
var parameters = <any>{};
358+
if (typeof user_id != "undefined") {
359+
parameters.user_id = user_id;
360+
}
361+
362+
try {
363+
await this.httpClient.get(
364+
"/" + item.getAppUUID().composedUUID() + "/indices/" + item.getIndexUUID().composedUUID() + "/items/" + item.getUUID().composedUUID() + '/click',
365+
"post",
366+
this.getCredentials(),
367+
parameters,
368+
{}
369+
);
370+
} catch (response) {
371+
throw this.createErrorFromResponse(response);
372+
}
373+
}
374+
345375
/**
346376
* Get query values
347377
*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { expect } from 'chai';
2+
import {Query} from "../../../src/Query/Query";
3+
import {Item} from "../../../src/Model/Item";
4+
import {ItemUUID} from "../../../src/Model/ItemUUID";
5+
import {IndexUUID} from "../../../src/Model/IndexUUID";
6+
import {Config} from "../../../src/Config/Config";
7+
import FunctionalTest from "./FunctionalTest";
8+
9+
/**
10+
*
11+
*/
12+
describe('Click', () => {
13+
const repository = FunctionalTest.createRepository();
14+
const indexUUID = IndexUUID.createById('default');
15+
16+
it('should properly make a click', async () => {
17+
try {
18+
await repository.deleteIndex(indexUUID);
19+
} catch(e) {}
20+
21+
await repository.createIndex(indexUUID, Config.createFromArray({}));
22+
const item1 = Item.create(ItemUUID.createByComposedUUID('1~item'));
23+
const item2 = Item.create(ItemUUID.createByComposedUUID('2~item'));
24+
repository.addItem(item1);
25+
repository.addItem(item2);
26+
await repository.flush();
27+
const result = await repository.query(Query.createMatchAll());
28+
const items = result.getItems();
29+
30+
await repository.click(items[0], 'user1234');
31+
await repository.click(items[1], 'user5678');
32+
});
33+
});

test/Model/Item.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ describe('Model/', () => {
213213
'type': 'product'
214214
}
215215
});
216-
expect(item.getScore()).to.be.equals(undefined);
217-
expect(item.toArray().score).to.be.equals(undefined);
216+
expect(item.getScore()).to.be.undefined;
217+
expect(item.toArray().score).to.be.undefined;
218218

219219
item = Item.createFromArray({
220220
'uuid': {
@@ -240,11 +240,11 @@ describe('Model/', () => {
240240
'type': 'product'
241241
}
242242
});
243-
expect(item.getAppUUID()).to.be.equals(undefined);
244-
expect(item.getIndexUUID()).to.be.equals(undefined);
243+
expect(item.getAppUUID()).to.be.undefined;
244+
expect(item.getIndexUUID()).to.be.undefined;
245245
item = Item.createFromArray(item.toArray());
246-
expect(item.getAppUUID()).to.be.equals(undefined);
247-
expect(item.getIndexUUID()).to.be.equals(undefined);
246+
expect(item.getAppUUID()).to.be.undefined;
247+
expect(item.getIndexUUID()).to.be.undefined;
248248

249249
let appUUID = AppUUID.createById('app1');
250250
let indexUUID = IndexUUID.createById('index1');

0 commit comments

Comments
 (0)