From 2fb15556e15032fc75a011a4a211a0ddd63c0706 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sat, 9 Nov 2019 08:07:05 +1000 Subject: [PATCH] More word filter tests. Fix WordFilters.Get. --- common/word_filters.go | 2 +- misc_test.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/common/word_filters.go b/common/word_filters.go index 798b74c3..7bd1fcfd 100644 --- a/common/word_filters.go +++ b/common/word_filters.go @@ -43,7 +43,7 @@ func NewDefaultWordFilterStore(acc *qgen.Accumulator) (*DefaultWordFilterStore, wf := "word_filters" store := &DefaultWordFilterStore{ getAll: acc.Select(wf).Columns("wfid,find,replacement").Prepare(), - get: acc.Select(wf).Columns("wfid,find,replacement").Where("wfid = ?").Prepare(), + get: acc.Select(wf).Columns("find,replacement").Where("wfid = ?").Prepare(), create: acc.Insert(wf).Columns("find,replacement").Fields("?,?").Prepare(), delete: acc.Delete(wf).Where("wfid = ?").Prepare(), update: acc.Update(wf).Set("find = ?, replacement = ?").Where("wfid = ?").Prepare(), diff --git a/misc_test.go b/misc_test.go index 9aba15af..75b3f753 100644 --- a/misc_test.go +++ b/misc_test.go @@ -1289,11 +1289,13 @@ func TestWordFilters(t *testing.T) { expect(t, len(filters) == 0, "Word filter map should be empty") // TODO: Add a test for ParseMessage relating to word filters - err = c.WordFilters.Create("imbecile", "lovely") + wfid, err := c.WordFilters.Create("imbecile", "lovely") expectNilErr(t, err) + expect(t,wfid == 1, "The first word filter should have an ID of 1") expect(t, c.WordFilters.Length() == 1, "Word filter list should not be empty") expect(t, c.WordFilters.EstCount() == 1, "Word filter list should not be empty") expect(t, c.WordFilters.Count() == 1, "Word filter list should not be empty") + filters, err = c.WordFilters.GetAll() expectNilErr(t, err) expect(t, len(filters) == 1, "Word filter map should not be empty") @@ -1301,9 +1303,18 @@ func TestWordFilters(t *testing.T) { expect(t, filter.ID == 1, "Word filter ID should be 1") expect(t, filter.Find == "imbecile", "Word filter needle should be imbecile") expect(t, filter.Replacement == "lovely", "Word filter replacement should be lovely") + + filter, err = c.WordFilters.Get(1) + expectNilErr(t, err) + expect(t, filter.ID == 1, "Word filter ID should be 1") + expect(t, filter.Find == "imbecile", "Word filter needle should be imbecile") + expect(t, filter.Replacement == "lovely", "Word filter replacement should be lovely") + // TODO: Add a test for ParseMessage relating to word filters - // TODO: Add deletion tests + err = c.WordFilters.Delete(1) + expectNilErr(t,err) + // TODO: More deletion tests } // TODO: Expand upon the valid characters which can go in URLs?