aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go110
1 files changed, 110 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go
new file mode 100644
index 0000000..aaf6ed3
--- /dev/null
+++ b/client_test.go
@@ -0,0 +1,110 @@
+// SPDX-FileCopyrightText: 2020 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package kamusku
+
+import (
+ "testing"
+
+ "git.sr.ht/~shulhan/kbbi"
+ "git.sr.ht/~shulhan/pakakeh.go/lib/test"
+)
+
+func TestApiClient_Lookup_offline(t *testing.T) {
+ testServer.offline = true
+
+ client := NewClient(testServerAPI)
+
+ cases := []struct {
+ desc string
+ words []string
+ exp kbbi.LookupResponse
+ expError string
+ }{{
+ desc: `With empty input`,
+ }, {
+ desc: `With words not found`,
+ words: []string{`a`},
+ }, {
+ desc: `With valid word in cache`,
+ words: []string{`mengeja`},
+ exp: kbbi.LookupResponse{
+ `mengeja`: testKataMengeja,
+ },
+ }, {
+ desc: `With duplicate words`,
+ words: []string{`mengeja`, `mengeja`},
+ exp: kbbi.LookupResponse{
+ `mengeja`: testKataMengeja,
+ },
+ }}
+
+ for _, c := range cases {
+ t.Logf(c.desc)
+
+ got, err := client.Lookup(c.words)
+ if err != nil {
+ test.Assert(t, `error`, c.expError, err.Error())
+ continue
+ }
+
+ test.Assert(t, `kbbi.LookupResponse`, c.exp, got)
+ }
+}
+
+func TestApiClient_Lookup_online(t *testing.T) {
+ t.Skip()
+
+ testServer.offline = false
+
+ client := NewClient(testServerAPI)
+
+ cases := []struct {
+ desc string
+ words []string
+ exp kbbi.LookupResponse
+ expError string
+ }{{
+ desc: `With empty input`,
+ }, {
+ desc: `With valid word in cache`,
+ words: []string{`mengeja`},
+ exp: kbbi.LookupResponse{
+ `mengeja`: testKataMengeja,
+ },
+ }, {
+ desc: `With duplicate words`,
+ words: []string{`mengeja`, `mengeja`},
+ exp: kbbi.LookupResponse{
+ `mengeja`: testKataMengeja,
+ },
+ }, {
+ desc: `With one of the word not in cache`,
+ words: []string{`mengeja`, `eja`},
+ exp: kbbi.LookupResponse{
+ `mengeja`: testKataMengeja,
+ `eja`: &kbbi.Word{
+ Definition: []*kbbi.WordDefinition{{
+ Value: `lafal huruf satu demi satu`,
+ Classes: []string{`Verba: kata kerja`},
+ }},
+ },
+ },
+ }}
+
+ for _, c := range cases {
+ t.Logf(c.desc)
+
+ got, err := client.Lookup(c.words)
+ if err != nil {
+ test.Assert(t, `error`, c.expError, err.Error())
+ continue
+ }
+
+ for k, v := range got {
+ t.Logf(`got: %s = %+v`, k, v)
+ }
+
+ test.Assert(t, `LookupResponse`, c.exp, got)
+ }
+}