~singpolyma/sgx-jmp

ref: 9440485fcd93b619a22e729cf591264b6569dcd4 sgx-jmp/test/test_trust_level_repo.rb -rw-r--r-- 2.4 KiB
9440485fStephen Paul Weber Merge branch 'more-admin-info' a 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
# frozen_string_literal: true

require "trust_level_repo"

class TrustLevelRepoTest < Minitest::Test
	def test_manual_tomb
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new(
				"jmp_customer_trust_level-test" => "Tomb"
			)
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_equal "Manual(Tomb)", trust_level.to_s
	end
	em :test_manual_tomb

	def test_manual_basement
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new(
				"jmp_customer_trust_level-test" => "Basement"
			)
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_equal "Manual(Basement)", trust_level.to_s
	end
	em :test_manual_basement

	def test_manual_customer
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new(
				"jmp_customer_trust_level-test" => "Customer"
			)
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_equal "Manual(Customer)", trust_level.to_s
	end
	em :test_manual_customer

	def test_manual_paragon
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new(
				"jmp_customer_trust_level-test" => "Paragon"
			)
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_equal "Manual(Paragon)", trust_level.to_s
	end
	em :test_manual_paragon

	def test_manual_unknown
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new(
				"jmp_customer_trust_level-test" => "UNKNOWN"
			)
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_equal "Manual(Customer)", trust_level.to_s
	end
	em :test_manual_unknown

	def test_new_customer
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new,
			redis: FakeRedis.new
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_kind_of TrustLevel::Basement, trust_level
	end
	em :test_new_customer

	def test_regular_customer
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new(["test"] => [{ "settled_amount" => 15 }]),
			redis: FakeRedis.new
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_kind_of TrustLevel::Customer, trust_level
	end
	em :test_regular_customer

	def test_settled_customer
		trust_level = TrustLevelRepo.new(
			db: FakeDB.new(["test"] => [{ "settled_amount" => 61 }]),
			redis: FakeRedis.new
		).find(OpenStruct.new(customer_id: "test", plan_name: "usd")).sync
		assert_kind_of TrustLevel::Paragon, trust_level
	end
	em :test_settled_customer
end