|
| 1 | +import chai from "chai"; |
| 2 | +import chaiAsPromised from "chai-as-promised"; |
| 3 | +import { Client as TypesenseClient } from "../../src/Typesense"; |
| 4 | +import ApiCall from "../../src/Typesense/ApiCall"; |
| 5 | +import axios from "axios"; |
| 6 | +import MockAxiosAdapter from "axios-mock-adapter"; |
| 7 | + |
| 8 | +let expect = chai.expect; |
| 9 | +chai.use(chaiAsPromised); |
| 10 | + |
| 11 | +describe("StemmingDictionary", function () { |
| 12 | + let typesense; |
| 13 | + let stemmingDictionary; |
| 14 | + let apiCall; |
| 15 | + let mockAxios; |
| 16 | + |
| 17 | + beforeEach(function () { |
| 18 | + typesense = new TypesenseClient({ |
| 19 | + nodes: [ |
| 20 | + { |
| 21 | + host: "node0", |
| 22 | + port: "8108", |
| 23 | + protocol: "http", |
| 24 | + }, |
| 25 | + ], |
| 26 | + apiKey: "abcd", |
| 27 | + randomizeNodes: false, |
| 28 | + }); |
| 29 | + stemmingDictionary = typesense.stemming.dictionaries("set1"); |
| 30 | + apiCall = new ApiCall(typesense.configuration); |
| 31 | + mockAxios = new MockAxiosAdapter(axios); |
| 32 | + }); |
| 33 | + |
| 34 | + describe(".retrieve", function () { |
| 35 | + it("retrieves the dictionary", function (done) { |
| 36 | + mockAxios |
| 37 | + .onGet( |
| 38 | + apiCall.uriFor( |
| 39 | + "/stemming/dictionaries/set1", |
| 40 | + typesense.configuration.nodes[0], |
| 41 | + ), |
| 42 | + null, |
| 43 | + { |
| 44 | + Accept: "application/json, text/plain, */*", |
| 45 | + "Content-Type": "application/json", |
| 46 | + "X-TYPESENSE-API-KEY": typesense.configuration.apiKey, |
| 47 | + }, |
| 48 | + ) |
| 49 | + .reply(200, { |
| 50 | + id: "set1", |
| 51 | + words: [{ word: "people", root: "person" }], |
| 52 | + }); |
| 53 | + |
| 54 | + let returnData = stemmingDictionary.retrieve(); |
| 55 | + |
| 56 | + expect(returnData) |
| 57 | + .to.eventually.deep.equal({ |
| 58 | + id: "set1", |
| 59 | + words: [{ word: "people", root: "person" }], |
| 60 | + }) |
| 61 | + .notify(done); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments