~singpolyma/jmp-pay

ref: 7958c1c5bb43796c0d02663965eee8c89112b812 jmp-pay/test/test_auto_top_up_repo.rb -rw-r--r-- 1.0 KiB
7958c1c5Stephen Paul Weber Factor out AutoTopUpRepo and add tests 10 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
# frozen_string_literal: true

require "test_helper"
require "auto_top_up_repo"

class AutoTopUpRepoTest < Minitest::Test
	def setup
		@redis = Minitest::Mock.new
		@db = Minitest::Mock.new
		@repo = AutoTopUpRepo.new(redis: @redis, db: @db)
	end

	property(:find) { string }
	def find(customer_id)
		@redis.expect(
			:get,
			nil,
			["jmp_customer_auto_top_up_amount-#{customer_id}"]
		)
		@repo.find(customer_id)
		assert_mock @redis
	end

	property(:put_valid_amount) { range(15, 9999999) }
	def put_valid_amount(amount)
		@redis.expect(
			:set,
			nil,
			["jmp_customer_auto_top_up_amount-somecustomer", amount]
		)
		@repo.put("somecustomer", amount)
		assert_mock @redis
	end

	property(:put_invalid_amount) { branch [:range, 1, 14], [:range, -999, -1] }
	def put_invalid_amount(amount)
		@repo.put("somecustomer", amount)
		assert_mock @redis
	end

	def test_put_zero
		@redis.expect(
			:del,
			nil,
			["jmp_customer_auto_top_up_amount-somecustomer"]
		)
		@repo.put("somecustomer", 0)
		assert_mock @redis
	end
end