Commit 50f1fc52 authored by Jyrki's avatar Jyrki 🐾

Add tests for WatchTargets repository

parent 7759ad81
......@@ -4,6 +4,10 @@ shards:
github: mamantoha/crest
version: 0.14.0
minitest:
github: ysbaddaden/minitest.cr
version: 0.4.0
pool:
github: ysbaddaden/pool
version: 0.2.3
......
......@@ -17,6 +17,10 @@ dependencies:
telegram_bot:
github: hangyas/telegram_bot
development_dependencies:
minitest:
github: ysbaddaden/minitest.cr
crystal: 0.26.1
license: MIT
require "./spec_helper"
describe BdNotifier do
# TODO: Write tests
it "works" do
false.should eq(true)
end
end
require "../spec_helper"
require "../../src/connection/redis"
require "../../src/repository/watch_targets"
module Repository
class WatchTargetsTest < Minitest::Test
def test_add
redis.hset "ddw:wt:nova", "Extralarge", "[420]"
Repository::WatchTargets.add(1337, "nova", BadDragon::Size::Extralarge)
users = JSON.parse(redis.hget("ddw:wt:nova", "Extralarge") || "[]").as_a.map(&.as_i)
assert_equal [420, 1337], users
end
def test_add_same_user
redis.hset "ddw:wt:nova", "Extralarge", "[420, 1337]"
Repository::WatchTargets.add(1337, "nova", BadDragon::Size::Extralarge)
users = JSON.parse(redis.hget("ddw:wt:nova", "Extralarge") || "[]").as_a.map(&.as_i)
assert_equal [420, 1337], users
end
def test_add_nonexistent_key
redis.del "ddw:wt:nova"
Repository::WatchTargets.add(1337, "nova", BadDragon::Size::Extralarge)
users = JSON.parse(redis.hget("ddw:wt:nova", "Extralarge") || "[]").as_a.map(&.as_i)
assert_equal [1337], users
end
def test_remove
redis.hset "ddw:wt:nova", "Extralarge", "[1337, 69, 420]"
Repository::WatchTargets.remove(69, "nova", BadDragon::Size::Extralarge)
users = JSON.parse(redis.hget("ddw:wt:nova", "Extralarge") || "[]").as_a.map(&.as_i)
assert_equal [1337, 420], users
end
def test_remove_nonexistent_user
redis.hset "ddw:wt:nova", "Extralarge", "[1337, 69, 420]"
Repository::WatchTargets.remove(666, "nova", BadDragon::Size::Extralarge)
users = JSON.parse(redis.hget("ddw:wt:nova", "Extralarge") || "[]").as_a.map(&.as_i)
assert_equal [1337, 69, 420], users
end
def test_remove_nonexistent_key
redis.del "ddw:wt:nova"
Repository::WatchTargets.remove(1337, "nova", BadDragon::Size::Extralarge)
redis_response = redis.hget("ddw:wt:nova", "Extralarge")
assert_equal "[]", redis_response
end
def test_watchers
redis.hset "ddw:wt:nova", "Extralarge", "[1337, 69, 420]"
users = Repository::WatchTargets.watchers("nova", BadDragon::Size::Extralarge)
assert_equal [1337, 69, 420], users
end
def test_watchers_nonexistent_key
redis.del "ddw:wt:nova"
users = Repository::WatchTargets.watchers("nova", BadDragon::Size::Extralarge)
assert_equal [] of Int32, users
end
private def redis
::Connection::Redis.connection
end
end
end
require "spec"
require "../src/bd_notifier"
require "minitest/autorun"
# mute the darn logger
require "../src/application"
class Application
@@logger = Logger.new(nil)
end
require "redis"
require "redis/pooled_client"
require "../application"
module Connection
class Redis
def self.connection
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment