1# frozen_string_literal: true
2
3require "test_helper"
4require_relative "../../sgx-bwmsgsv2"
5require "rantly/minitest_extensions"
6require_relative "rantly_extensions/data_extensions"
7
8class ToCatapultPropertyTest < Minitest::Test
9 def test_accepts_201_and_202_with_escaped_tag
10 property_of {
11 dest = nanpa_phone
12 guard(dest != "+15550000000")
13
14 stanza_id = maybe_http_escapable_string
15 resource = maybe_http_escapable_string
16 status = choose(201, 202)
17
18 [dest, message_body(nil_pct: 0, empty_pct: 0), stanza_id, resource, status]
19 }.check { |dest, body, stanza_id, resource, status|
20 reset_stanzas!
21 reset_redis!
22 WebMock.reset!
23
24 bw_request_body = nil
25 bw_req = stub_request(:post, BW_MESSAGES_URL).to_return { |request|
26 bw_request_body = JSON.parse(request.body)
27 {
28 status: status,
29 body: JSON.dump(id: "bw-msg-id", time: Time.now.iso8601)
30 }
31 }
32
33 m = Blather::Stanza::Message.new("#{dest}@component", body)
34 m.from = "test@example.com/#{resource}"
35 m.id = stanza_id
36
37 process_stanza(m)
38
39 expected_tag = WEBrick::HTTPUtils.escape(stanza_id) +
40 " " +
41 WEBrick::HTTPUtils.escape(resource)
42 assert_equal expected_tag, bw_request_body["tag"],
43 "Tag should be HTTP-escaped (status=#{status})"
44
45 assert_requested bw_req
46
47 written.each do |response|
48 stanza = Blather::XMPPNode.parse(response.to_xml)
49 refute stanza.error?,
50 "Expected success for status #{status} but got error"
51 end
52 }
53 end
54 em :test_accepts_201_and_202_with_escaped_tag
55end