1 // Copyright (c) 2020 650 Industries, Inc. All rights reserved. 2 3 import ExpoModulesTestCore 4 5 @testable import EXUpdates 6 7 class ResponseHeaderDataSpec : ExpoSpec { specnull8 override func spec() { 9 describe("dictionaryWithStructuredHeader") { 10 it("SupportedTypes") { 11 let header = "string=\"string-0000\", true=?1, false=?0, integer=47, decimal=47.5" 12 let expected: [String : Any] = [ 13 "string": "string-0000", 14 "true": true, 15 "false": false, 16 "integer": 47, 17 "decimal": 47.5 18 ] 19 let actual = ResponseHeaderData.dictionaryWithStructuredHeader(header) 20 expect(NSDictionary(dictionary: expected).isEqual(to: actual!)).to(beTrue()) 21 } 22 23 it("IgnoresOtherTypes") { 24 let header = "branch-name=\"rollout-1\", data=:w4ZibGV0w6ZydGUK:, list=(1 2)" 25 let expected: [String : Any] = [ 26 "branch-name": "rollout-1" 27 ] 28 let actual = ResponseHeaderData.dictionaryWithStructuredHeader(header) 29 expect(NSDictionary(dictionary: expected).isEqual(to: actual!)).to(beTrue()) 30 } 31 32 it("IgnoresParameters") { 33 let header = "abc=123;a=1;b=2" 34 let expected: [String : Any] = [ 35 "abc": 123 36 ] 37 let actual = ResponseHeaderData.dictionaryWithStructuredHeader(header) 38 expect(NSDictionary(dictionary: expected).isEqual(to: actual!)).to(beTrue()) 39 } 40 41 it("Empty") { 42 let header = "" 43 let expected: [String : Any] = [:] 44 let actual = ResponseHeaderData.dictionaryWithStructuredHeader(header) 45 expect(NSDictionary(dictionary: expected).isEqual(to: actual!)).to(beTrue()) 46 } 47 48 it("ParsingError") { 49 let header = "bad dictionary" 50 expect(ResponseHeaderData.dictionaryWithStructuredHeader(header)).to(beNil()) 51 } 52 } 53 } 54 } 55