~singpolyma/sgx-jmp

9d529fc0c262c5700739071291c95a944559b9b2 — root21 1 year, 7 months ago 245f384
SIM nicknames feature

Added columns to the eSIMs command to now display the nickname of a SIM,
if set.
Added test for the new columns in sim_repo.
Added nicknames column to sims form, and modified to a multiline form.
5 files changed, 14 insertions(+), 5 deletions(-)

M forms/sim_details.rb
M lib/sim.rb
M lib/sim_repo.rb
M schemas
M test/test_sim_repo.rb
M forms/sim_details.rb => forms/sim_details.rb +6 -1
@@ 1,4 1,9 @@
result!
title "(e)SIM Details"

table(@sims, iccid: "ICCID", remaining_usage_mb: "MB Remaining")
table(
	@sims,
	iccid: "ICCID",
	remaining_usage_mb: "MB Remaining",
	nickname: "Nickname"
)

M lib/sim.rb => lib/sim.rb +1 -0
@@ 9,6 9,7 @@ class SIM
		remaining_usage_kb Integer
		remaining_days Integer
		notes String
		nickname Either(String, nil), default: nil
	end

	def self.extract(kwargs)

M lib/sim_repo.rb => lib/sim_repo.rb +4 -2
@@ 26,10 26,12 @@ class SIMRepo
	def owned_by(customer)
		customer = customer.customer_id if customer.respond_to?(:customer_id)
		promise = db.query_defer(<<~SQL, [customer])
			SELECT iccid FROM sims WHERE customer_id=$1
			SELECT iccid, nickname FROM sims WHERE customer_id=$1
		SQL
		promise.then { |result|
			EMPromise.all(result.map { |row| find(row["iccid"]) })
			EMPromise.all(result.map { |row|
				find(row["iccid"]).then { |sim| sim.with(nickname: row["nickname"]) }
			})
		}
	end
end

M schemas => schemas +1 -1
@@ 1,1 1,1 @@
Subproject commit a449672f5cad37e63e6339e4577ed27ff8289df9
Subproject commit a9f8b83487140f91fc8da3a3de99f5f28aa060b9

M test/test_sim_repo.rb => test/test_sim_repo.rb +2 -1
@@ 7,7 7,7 @@ class SIMRepoTest < Minitest::Test
	def setup
		@repo = SIMRepo.new(
			db: FakeDB.new(
				["test"] => [{ "iccid" => "1234" }]
				["test"] => [{ "iccid" => "1234", "nickname" => "My Cool SIM" }]
			)
		)
	end


@@ 33,6 33,7 @@ class SIMRepoTest < Minitest::Test
		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