Example #1
0
func TestChannelSetAPI(t *testing.T) {
	conf := getConfig()

	Convey("Given a clean database and an API instance", t, func() {
		db, err := OpenDatabase(conf.PostgresDSN)
		So(err, ShouldBeNil)
		mustResetDB(db)

		ctx := Context{
			DB: db,
		}
		api := NewChannelListAPI(ctx)

		cl := models.ChannelList{
			Name: "test set",
		}

		Convey("When calling Create", func() {
			So(api.Create(cl, &cl.ID), ShouldBeNil)

			Convey("Then the channel-list has been created", func() {
				var cl2 models.ChannelList
				So(api.Get(cl.ID, &cl2), ShouldBeNil)
				So(cl2, ShouldResemble, cl)

				Convey("Then the channel-list can be updated", func() {
					cl.Name = "test set 2"
					So(api.Update(cl, &cl.ID), ShouldBeNil)
					So(api.Get(cl.ID, &cl2), ShouldBeNil)
					So(cl2, ShouldResemble, cl)
				})

				Convey("Then the channel-list can be deleted", func() {
					So(api.Delete(cl.ID, &cl.ID), ShouldBeNil)
					So(api.Get(cl.ID, &cl2), ShouldNotBeNil)
				})
			})

			Convey("Then the list of channel-list has size 1", func() {
				var list []models.ChannelList
				So(api.GetList(models.GetListRequest{
					Limit:  10,
					Offset: 0,
				}, &list), ShouldBeNil)
				So(list, ShouldHaveLength, 1)
			})
		})
	})
}
Example #2
0
func TestChannelFunctions(t *testing.T) {
	conf := common.GetTestConfig()

	Convey("Given a clean database", t, func() {
		db, err := OpenDatabase(conf.PostgresDSN)
		So(err, ShouldBeNil)
		common.MustResetDB(db)

		Convey("When creating a channel-list", func() {
			cl := models.ChannelList{
				Name: "test channel-list",
			}
			So(CreateChannelList(db, &cl), ShouldBeNil)

			Convey("Then the channel-list exists", func() {
				cl2, err := GetChannelList(db, cl.ID)
				So(err, ShouldBeNil)
				So(cl2, ShouldResemble, cl)
			})

			Convey("When updating the channel-list", func() {
				cl.Name = "test channel-list changed"
				So(UpdateChannelList(db, cl), ShouldBeNil)

				Convey("Then the channel-list has been updated", func() {
					cl2, err := GetChannelList(db, cl.ID)
					So(err, ShouldBeNil)
					So(cl2, ShouldResemble, cl)
				})
			})

			Convey("Then listing the channel-lists returns 1 result", func() {
				lists, err := GetChannelLists(db, 10, 0)
				So(err, ShouldBeNil)
				So(lists, ShouldHaveLength, 1)
				So(lists[0], ShouldResemble, cl)
			})

			Convey("Then the channel-list count returns 1", func() {
				count, err := GetChannelListsCount(db)
				So(err, ShouldBeNil)
				So(count, ShouldEqual, 1)
			})

			Convey("When deleting the channel-list", func() {
				So(DeleteChannelList(db, cl.ID), ShouldBeNil)

				Convey("Then the channel-list has been removed", func() {
					count, err := GetChannelListsCount(db)
					So(err, ShouldBeNil)
					So(count, ShouldEqual, 0)
				})
			})

			Convey("When creating a channel", func() {
				c := models.Channel{
					ChannelListID: cl.ID,
					Channel:       4,
					Frequency:     868700000,
				}
				So(CreateChannel(db, &c), ShouldBeNil)

				Convey("Then the channel has been created", func() {
					c2, err := GetChannel(db, c.ID)
					So(err, ShouldBeNil)
					So(c2, ShouldResemble, c)
				})

				Convey("When updating the channel", func() {
					c.Channel = 5
					So(UpdateChannel(db, c), ShouldBeNil)

					Convey("Then the channel has been updated", func() {
						c2, err := GetChannel(db, c.ID)
						So(err, ShouldBeNil)
						So(c2, ShouldResemble, c)
					})
				})

				Convey("When deleting the channel", func() {
					So(DeleteChannel(db, c.ID), ShouldBeNil)

					Convey("Then the channel has been deleted", func() {
						_, err := GetChannel(db, c.ID)
						So(err, ShouldNotBeNil)
					})
				})

				Convey("When getting all channels for the channel-list", func() {
					channels, err := GetChannelsForChannelList(db, cl.ID)
					So(err, ShouldBeNil)

					Convey("Then it contains the channel", func() {
						So(channels, ShouldHaveLength, 1)
						So(channels[0], ShouldResemble, c)
					})
				})
			})
		})
	})
}