Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Strengthen test bike registration #20

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 8 additions & 40 deletions BikeIndex/Model/Registering/BikeRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ struct BikeRegistration: Encodable {
let color: String
let primary_frame_color: String

let test: Bool
#if DEBUG
/// Test bikes do not send registration emails and are automatically removed.
var test = true
#endif

// MARK: Optional fields
var owner_email_is_phone_number: Bool?
Expand Down Expand Up @@ -53,40 +56,6 @@ struct BikeRegistration: Encodable {
var stolen_record: StolenRecord?
var components: [Component]?

init(serial: String?, manufacturer: String, owner_email: String, primary_frame_color: FrameColor, test: Bool = false, owner_email_is_phone_number: Bool? = nil, organization_slug: String? = nil, cycle_type_name: BicycleType? = nil, no_duplicate: Bool? = nil, rear_wheel_bsd: Int? = nil, rear_tire_narrow: Bool? = nil, front_wheel_bsd: String? = nil, front_tire_narrow: Bool? = nil, frame_model: String? = nil, year: UInt? = nil, description: String? = nil, secondary_frame_color: FrameColor? = nil, tertiary_frame_color: FrameColor? = nil, rear_gear_type_slug: String? = nil, front_gear_type_slug: String? = nil, extra_registration_number: String? = nil, handlebar_type_slug: String? = nil, no_notify: Bool? = nil, is_for_sale: Bool? = nil, frame_material: String, external_image_urls: [URL]? = nil, bike_sticker: String? = nil, propulsion: Propulsion? = nil, stolen_record: StolenRecord? = nil, components: [Component]? = nil) {
self.serial = serial ?? Serial.unknown
self.manufacturer = manufacturer
self.owner_email = owner_email
self.primary_frame_color = primary_frame_color.rawValue.lowercased()
self.color = primary_frame_color.rawValue.lowercased()
self.test = test
self.owner_email_is_phone_number = owner_email_is_phone_number
self.organization_slug = organization_slug
self.cycle_type_name = cycle_type_name
self.no_duplicate = no_duplicate
self.rear_wheel_bsd = rear_wheel_bsd
self.rear_tire_narrow = rear_tire_narrow
self.front_wheel_bsd = front_wheel_bsd
self.front_tire_narrow = front_tire_narrow
self.frame_model = frame_model
self.year = year
self.description = description
self.secondary_frame_color = secondary_frame_color?.rawValue.lowercased()
self.tertiary_frame_color = tertiary_frame_color?.rawValue.lowercased()
self.rear_gear_type_slug = rear_gear_type_slug
self.front_gear_type_slug = front_gear_type_slug
self.extra_registration_number = extra_registration_number
self.handlebar_type_slug = handlebar_type_slug
self.no_notify = no_notify
self.is_for_sale = is_for_sale
self.frame_material = frame_material
self.external_image_urls = external_image_urls
self.bike_sticker = bike_sticker
self.propulsion = propulsion
self.stolen_record = stolen_record
self.components = components
}

init(bike: Bike,
mode: RegisterMode,
stolen: StolenRecord?,
Expand All @@ -100,8 +69,7 @@ struct BikeRegistration: Encodable {
self.manufacturer = bike.manufacturerName
self.primary_frame_color = bike.frameColorPrimary.rawValue.lowercased()
self.color = bike.frameColorPrimary.rawValue.lowercased()
self.owner_email = ownerEmail // Bike<->User relationships are not yet established
self.test = false
self.owner_email = ownerEmail

// Non-required fields
self.secondary_frame_color = bike.frameColorSecondary?.rawValue.lowercased()
Expand All @@ -121,7 +89,7 @@ struct BikeRegistration: Encodable {
self.stolen_record = nil
}

// Unsupported fields for future work
// TODO: Unsupported fields, support in future changes
self.owner_email_is_phone_number = nil
self.organization_slug = nil
self.no_duplicate = nil
Expand Down Expand Up @@ -219,8 +187,8 @@ struct BikeRegistration: Encodable {
try container.encodeIfPresent(self.stolen_record, forKey: .stolen_record)
try container.encodeIfPresent(self.components, forKey: .components)

#if !RELEASE
try container.encode(true, forKey: .test)
#if DEBUG
try container.encode(test, forKey: .test)
#endif

// Propulsion subtype
Expand Down