# frozen_string_literal: true

require "test_helper"
require "sim_repo"

class SIMRepoTest < Minitest::Test
	def setup
		@repo = SIMRepo.new(
			db: FakeDB.new(
				["test"] => [{ "iccid" => "1234", "nickname" => "My Cool SIM" }]
			)
		)
	end

	def test_owned_by
		req = stub_request(
			:get,
			"https://myaccount.keepgo.com/api/v2/line/1234/get_details"
		).with(
			headers: {
				"Accept" => "application/json",
				"Accesstoken" => "keepgotoken",
				"Apikey" => "keepgokey"
			}
		).to_return(status: 200, body: { sim_card: {
			iccid: "1234",
			lpa_code: "LPA:dummy",
			remaining_usage_kb: 1024,
			remaining_days: 365,
			notes: ""
		} }.to_json)

		sims = @repo.owned_by("test").sync
		assert_equal 1, sims.length
		assert_equal "1234", sims[0].iccid
		assert_equal "My Cool SIM", sims[0].nickname
		assert_requested req
	end
	em :test_owned_by
end
