~singpolyma/sgx-jmp

ref: 71349efa852cc2c469492d2e34c6a1c3cb3fb6c2 sgx-jmp/test/test_command_list.rb -rw-r--r-- 2.1 KiB
71349efaStephen Paul Weber Factor out CustomerRepo 1 year, 1 month 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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
		assert_instance_of CommandList, CommandList.for(nil).sync
	end
	em :test_for_no_customer

	def test_for_unregistered
		customer = OpenStruct.new(registered?: false)
		assert_instance_of CommandList, CommandList.for(customer).sync
	end
	em :test_for_unregistered

	def test_for_registered
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve(nil),
			["catapult_fwd-1"]
		)
		customer = OpenStruct.new(
			registered?: OpenStruct.new(phone: "1"),
			payment_methods: EMPromise.resolve([])
		)
		assert_equal(
			["CommandList::Registered"],
			CommandList.for(customer).sync
			.class.ancestors.map(&:name).grep(/\ACommandList::/)
		)
	end
	em :test_for_registered

	def test_for_registered_with_fwd
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve("tel:1"),
			["catapult_fwd-1"]
		)
		customer = OpenStruct.new(
			registered?: OpenStruct.new(phone: "1"),
			payment_methods: EMPromise.resolve([])
		)
		assert_equal(
			CommandList::HAS_FORWARDING,
			CommandList::HAS_FORWARDING & CommandList.for(customer).sync.to_a
		)
	end
	em :test_for_registered_with_fwd

	def test_for_registered_with_credit_card
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve(nil),
			["catapult_fwd-1"]
		)
		customer = OpenStruct.new(
			registered?: OpenStruct.new(phone: "1"),
			plan_name: "test",
			payment_methods: EMPromise.resolve([:boop])
		)
		assert_equal(
			CommandList::HAS_CREDIT_CARD,
			CommandList::HAS_CREDIT_CARD & CommandList.for(customer).sync.to_a
		)
	end
	em :test_for_registered_with_credit_card

	def test_for_registered_with_currency
		CommandList::REDIS.expect(
			:get,
			EMPromise.resolve(nil),
			["catapult_fwd-1"]
		)
		customer = OpenStruct.new(
			registered?: OpenStruct.new(phone: "1"),
			currency: :USD
		)

		assert_equal(
			CommandList::HAS_CURRENCY,
			CommandList::HAS_CURRENCY & CommandList.for(customer).sync.to_a
		)
	end
	em :test_for_registered_with_currency
end