1# frozen_string_literal: true
2
3require "test_helper"
4require "sim_repo"
5
6class SIMRepoTest < Minitest::Test
7 def setup
8 @repo = SIMRepo.new(
9 db: FakeDB.new(
10 ["test"] => [{ "iccid" => "1234", "nickname" => "My Cool SIM" }]
11 )
12 )
13 end
14
15 def test_owned_by
16 req = stub_request(
17 :get,
18 "https://myaccount.keepgo.com/api/v2/line/1234/get_details"
19 ).with(
20 headers: {
21 "Accept" => "application/json",
22 "Accesstoken" => "keepgotoken",
23 "Apikey" => "keepgokey"
24 }
25 ).to_return(status: 200, body: { sim_card: {
26 iccid: "1234",
27 lpa_code: "LPA:dummy",
28 remaining_usage_kb: 1024,
29 remaining_days: 365,
30 notes: ""
31 } }.to_json)
32
33 sims = @repo.owned_by("test").sync
34 assert_equal 1, sims.length
35 assert_equal "1234", sims[0].iccid
36 assert_equal "My Cool SIM", sims[0].nickname
37 assert_requested req
38 end
39 em :test_owned_by
40end