Skip to content
This repository has been archived by the owner on Nov 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from Fallenstedt/story/rule-builder-test
Browse files Browse the repository at this point in the history
add rule builder tests
  • Loading branch information
Fallenstedt authored Dec 11, 2021
2 parents 76c4cff + 156bac2 commit 1c661f7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions rules/rule_builder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package rules

import (
"encoding/json"
"testing"
)

func TestNewDeleteRulesRequestAcceptsMultipleIds(t *testing.T) {
result := NewDeleteRulesRequest(1, 2, 3, 4, 5)
expected := []int{1, 2, 3, 4, 5}

if len(result.Delete.Ids) != len(expected) {
t.Errorf("Expected %v to have same length as %v", result, expected)
}

for i := range result.Delete.Ids {
if result.Delete.Ids[i] != expected[i] {
t.Errorf("Expected %v to equal %v", result.Delete.Ids[i], expected[i])
}
}
}

func TestNewDeleteRulesRequestMarshalsWell(t *testing.T) {
result := NewDeleteRulesRequest(1, 2, 3, 4, 5)
body, err := json.Marshal(result)

if err != nil {
t.Error(err)
}

if string(body) != "{\"delete\":{\"ids\":[1,2,3,4,5]}}" {
t.Errorf("Expected %v to equal %v", string(body), "{\"delete\":{\"ids\":[1,2,3,4,5]}}")
}
}

func TestNewRuleBuilderBuildsManyRules(t *testing.T) {
result := NewRuleBuilder().AddRule("cats", "cat tweets").AddRule("dogs", "dog tweets").Build()
body, err := json.Marshal(result)

if err != nil {
t.Error(err)
}

if string(body) != "{\"add\":[{\"value\":\"cats\",\"tag\":\"cat tweets\"},{\"value\":\"dogs\",\"tag\":\"dog tweets\"}]}" {
t.Errorf("Expected %v to equal %v", string(body), "{\"add\":[{\"value\":\"cats\",\"tag\":\"cat tweets\"},{\"value\":\"dogs\",\"tag\":\"dog tweets\"}]}")
}
}

0 comments on commit 1c661f7

Please sign in to comment.