From 8c8f1bdd633f3afe158dd8c02130a36a5ca9be9d Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 1 Oct 2015 14:10:52 -0400 Subject: [PATCH] Add model test for outgoing webhooks. --- ...bhook_test.go => incoming_webhook_test.go} | 0 model/outgoing_webhook_test.go | 97 +++++++++++++++++++ 2 files changed, 97 insertions(+) rename model/{webhook_test.go => incoming_webhook_test.go} (100%) create mode 100644 model/outgoing_webhook_test.go diff --git a/model/webhook_test.go b/model/incoming_webhook_test.go similarity index 100% rename from model/webhook_test.go rename to model/incoming_webhook_test.go diff --git a/model/outgoing_webhook_test.go b/model/outgoing_webhook_test.go new file mode 100644 index 0000000000..2ca48c2910 --- /dev/null +++ b/model/outgoing_webhook_test.go @@ -0,0 +1,97 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "strings" + "testing" +) + +func TestOutgoingWebhookJson(t *testing.T) { + o := OutgoingWebhook{Id: NewId()} + json := o.ToJson() + ro := OutgoingWebhookFromJson(strings.NewReader(json)) + + if o.Id != ro.Id { + t.Fatal("Ids do not match") + } +} + +func TestOutgoingWebhookIsValid(t *testing.T) { + o := OutgoingWebhook{} + + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Id = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.UpdateAt = GetMillis() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreatorId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CreatorId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Token = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.Token = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ChannelId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.ChannelId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = "123" + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.TeamId = NewId() + if err := o.IsValid(); err == nil { + t.Fatal("should be invalid") + } + + o.CallbackURLs = []string{"http://nowhere.com/"} + if err := o.IsValid(); err != nil { + t.Fatal(err) + } +} + +func TestOutgoingWebhookPreSave(t *testing.T) { + o := OutgoingWebhook{} + o.PreSave() +} + +func TestOutgoingWebhookPreUpdate(t *testing.T) { + o := OutgoingWebhook{} + o.PreUpdate() +}