summaryrefslogtreecommitdiff
path: root/tests/ruby.rb
diff options
context:
space:
mode:
authorTommaso Negri <tommaso@hey.com>2025-12-05 17:50:04 +0100
committerTommaso Negri <tommaso@hey.com>2025-12-05 17:50:04 +0100
commitf9e2bdfd8285107572a356646b0a70d5a03136e7 (patch)
treeacbc8408fbf3cb35940cce8bea59b32cd6dcc435 /tests/ruby.rb
parent804891fd726137e024292149bbf67083fd0a422d (diff)
downloadvoltage-f9e2bdfd8285107572a356646b0a70d5a03136e7.tar.gz
voltage-f9e2bdfd8285107572a356646b0a70d5a03136e7.zip
Add test files
Diffstat (limited to 'tests/ruby.rb')
-rw-r--r--tests/ruby.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ruby.rb b/tests/ruby.rb
new file mode 100644
index 0000000..004d516
--- /dev/null
+++ b/tests/ruby.rb
@@ -0,0 +1,49 @@
+class App < Struct.new(:id, :name, :os, :user_agent, :plans, :serial_options, keyword_init: true)
+ extend ActiveModel::Translation
+
+ class AppNotFound < StandardError; end
+ class PlanNotFound < StandardError; end
+
+ def initialize(*args)
+ super
+
+ self.plans.map! { |plan| Plan.new(**plan) }
+ self.serial_options = SerialOptions.new(**self.serial_options)
+ end
+
+ def icon
+ "apps/#{id}.png"
+ end
+
+ def find_plan(id)
+ plans.detect { |plan| plan.id == id } || (raise PlanNotFound)
+ end
+
+ def download_link
+ "https://services.panini.house/apps/#{id}/latest_releases"
+ end
+
+ def download_link_for(serial_number)
+ "#{download_link}?serial_number=#{serial_number}"
+ end
+
+ def marketing_list
+ Sendy.lists.optional[id]
+ end
+
+ def checkout_recovery_list
+ Sendy.lists.optional["#{id}_checkout_recovery"]
+ end
+
+ def self.all
+ template = ERB.new File.read(Rails.root.join("app", "data", "apps.yml.erb"))
+
+ YAML.load(template.result)
+ .map(&:with_indifferent_access)
+ .map { |app| new(**app) }
+ end
+
+ def self.find(id)
+ all.find { |app| app.id == id } || (raise AppNotFound)
+ end
+end