~singpolyma/sgx-jmp

ref: 345895de5e28ddf4e57ae13599924149f5d44d5c sgx-jmp/test/test_command_list.rb -rw-r--r-- 1.4 KiB
345895deStephen Paul Weber Show commands conditionally (plus add voicemail record command) 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require "test_helper"
require "command_list"

CommandList::Customer = Minitest::Mock.new
CommandList::REDIS = Minitest::Mock.new

class CommandListTest < Minitest::Test
	def test_for_no_customer
		CommandList::Customer.expect(
			:for_jid,
			EMPromise.reject("not found"),
			["none"]
		)
		assert_instance_of CommandList, CommandList.for("none").sync
	end
	em :test_for_no_customer

	def test_for_unregistered
		CommandList::Customer.expect(
			:for_jid,
			EMPromise.resolve(OpenStruct.new(registered?: false)),
			["unregistered"]
		)
		assert_instance_of CommandList, CommandList.for("unregistered").sync
	end
	em :test_for_unregistered

	def test_for_registered
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve(nil),
			["catapult_fwd-1"]
		)
		CommandList::Customer.expect(
			:for_jid,
			EMPromise.resolve(OpenStruct.new(registered?: OpenStruct.new(phone: "1"))),
			["registered"]
		)
		assert_instance_of CommandList::Registered, CommandList.for("registered").sync
	end
	em :test_for_registered

	def test_for_registered_with_fwd
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve("tel:1"),
			["catapult_fwd-1"]
		)
		CommandList::Customer.expect(
			:for_jid,
			EMPromise.resolve(OpenStruct.new(registered?: OpenStruct.new(phone: "1"))),
			["registered"]
		)
		assert_instance_of(
			CommandList::RegisteredAndHasForwarding,
			CommandList.for("registered").sync
		)
	end
	em :test_for_registered_with_fwd
end