Testing QueryString Parameter Parsing in Postal Server
This test suite validates the QueryString class functionality in Postal, focusing on parsing and handling query string parameters for email-related operations. The tests verify various input formats and edge cases for email address parsing and parameter handling.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
postalserver/postal
spec/lib/query_string_spec.rb
# frozen_string_literal: true
require "rails_helper"
describe QueryString do
it "works with a single item" do
qs = described_class.new("to: [email protected]")
expect(qs.hash["to"]).to eq "[email protected]"
end
it "works with a multiple items" do
qs = described_class.new("to: [email protected] from: [email protected]")
expect(qs.hash["to"]).to eq "[email protected]"
expect(qs.hash["from"]).to eq "[email protected]"
end
it "does not require a space after the field name" do
qs = described_class.new("to:[email protected] from:[email protected]")
expect(qs.hash["to"]).to eq "[email protected]"
expect(qs.hash["from"]).to eq "[email protected]"
end
it "returns nil when it receives blank" do
qs = described_class.new("to:[blank]")
expect(qs.hash["to"]).to eq nil
end
it "handles dates with spaces" do
qs = described_class.new("date: 2017-02-12 15:20")
expect(qs.hash["date"]).to eq("2017-02-12 15:20")
end
it "returns an array for multiple items" do
qs = described_class.new("to: [email protected] to: [email protected]")
expect(qs.hash["to"]).to be_a(Array)
expect(qs.hash["to"][0]).to eq "[email protected]"
expect(qs.hash["to"][1]).to eq "[email protected]"
end
it "works with a z in the string" do
qs = described_class.new("to: [email protected]")
expect(qs.hash["to"]).to eq "[email protected]"
end
end