If you would like to unsubscribe and stop receiving these emails <% click here %>.
" 43 | } 44 | 45 | /// Constants for custom arguments. 46 | public struct CustomArguments { 47 | /// The maximum number of bytes allowed for custom arguments in an email. 48 | public static let MaximumBytes: Int = 10000 49 | } 50 | 51 | /// Constants for ASM. 52 | public struct UnsubscribeGroups { 53 | /// The maximum number of unsubscribe groups you can specify in the 54 | /// `groupsToDisplay` property. 55 | public static let MaximumNumberOfDisplayGroups: Int = 25 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sources/SendGrid/Structs/DecodingStrategy.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// This struct houses both the date and data decoding strategies for a 4 | /// response. 5 | public struct DecodingStrategy { 6 | // MARK: - Properties 7 | 8 | /// The encoding strategy for dates. 9 | public let dates: JSONDecoder.DateDecodingStrategy 10 | 11 | /// The encoding strategy for data. 12 | public let data: JSONDecoder.DataDecodingStrategy 13 | 14 | // MARK: - Initialization 15 | 16 | /// Initializes the struct with a date and data strategy. 17 | /// 18 | /// - Parameters: 19 | /// - dates: The date encoding strategy. 20 | /// - data: The data encoding strategy. 21 | public init(dates: JSONDecoder.DateDecodingStrategy = .secondsSince1970, data: JSONDecoder.DataDecodingStrategy = .base64) { 22 | self.dates = dates 23 | self.data = data 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sources/SendGrid/Structs/EncodingStrategy.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// This struct houses both the date and data encoding strategies for a request. 4 | public struct EncodingStrategy { 5 | // MARK: - Properties 6 | 7 | /// The encoding strategy for dates. 8 | public let dates: JSONEncoder.DateEncodingStrategy 9 | 10 | /// The encoding strategy for data. 11 | public let data: JSONEncoder.DataEncodingStrategy 12 | 13 | // MARK: - Initialization 14 | 15 | /// Initializes the struct with a date and data strategy. 16 | /// 17 | /// - Parameters: 18 | /// - dates: The date encoding strategy. 19 | /// - data: The data encoding strategy. 20 | public init(dates: JSONEncoder.DateEncodingStrategy = .secondsSince1970, data: JSONEncoder.DataEncodingStrategy = .base64) { 21 | self.dates = dates 22 | self.data = data 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/SendGrid/Structs/Page.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// This struct is used to represent a page via the `limit` and `offset` 4 | /// parameters found in various API calls. 5 | public struct Page { 6 | // MARK: - Properties 7 | 8 | /// The limit value for each page of results. 9 | public let limit: Int 10 | 11 | /// The offset value for the page. 12 | public let offset: Int 13 | 14 | // MARK: - Initialization 15 | 16 | /// Initializes the struct with a limit and offset. 17 | /// 18 | /// - Parameters: 19 | /// - limit: The number of results per page. 20 | /// - offset: The index to start the page on. 21 | public init(limit: Int, offset: Int) { 22 | self.limit = limit 23 | self.offset = offset 24 | } 25 | } 26 | 27 | extension Page: Equatable { 28 | /// :nodoc: 29 | /// Equatable conformance. 30 | public static func ==(lhs: Page, rhs: Page) -> Bool { 31 | lhs.limit == rhs.limit && lhs.offset == rhs.offset 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Sources/SendGrid/Structs/Pagination.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | #if os(Linux) 3 | import FoundationNetworking 4 | #endif 5 | 6 | /// The `Pagination` struct represents all the pagination info that can be 7 | /// returned via an API call, often containing a `first`, `previous`, `next`, 8 | /// and `last` page. This struct represents all those pages as `Page` instances. 9 | public struct Pagination { 10 | // MARK: - Properties 11 | 12 | /// The first page of results. 13 | public let first: Page? 14 | 15 | /// The previous page of results. 16 | public let previous: Page? 17 | 18 | /// The next page of results. 19 | public let next: Page? 20 | 21 | /// The last page of results. 22 | public let last: Page? 23 | 24 | // MARK: - Initialization 25 | 26 | /// Initializes the struct with a first, previous, next, and last page. 27 | /// 28 | /// - Parameters: 29 | /// - first: The first page of results. 30 | /// - previous: The previous page of results. 31 | /// - next: The next page of results. 32 | /// - last: The last page of results. 33 | public init(first: Page? = nil, previous: Page? = nil, next: Page? = nil, last: Page? = nil) { 34 | self.first = first 35 | self.previous = previous 36 | self.next = next 37 | self.last = last 38 | } 39 | 40 | /// Initializes a new instance from the headers of an API response. 41 | /// 42 | /// - Parameter headers: The headers of the API response. 43 | public init?(headers: [AnyHashable: Any]) { 44 | guard let link = headers["Link"] as? String else { return nil } 45 | func first(match pattern: String, in str: String) -> String? { 46 | let range = str.startIndex..Hello World
") 9 | let onExpectations: [String: Any] = [ 10 | "enable": true, 11 | "text": "Hello World", 12 | "html": "Hello World
" 13 | ] 14 | XCTAssertEncodedObject(onSetting, equals: onExpectations) 15 | 16 | let offSetting = Footer() 17 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Mail/MailSettingsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class MailSettingsTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = MailSettings 6 | 7 | func testEncoding() { 8 | var settings = MailSettings() 9 | settings.bcc = BCCSetting(email: "foo@example.none") 10 | settings.bypassListManagement = BypassListManagement() 11 | settings.footer = Footer(text: "Hello World", html: "Hello World
") 12 | settings.sandboxMode = SandboxMode() 13 | settings.spamCheck = SpamChecker(threshold: 8) 14 | let expected: [String: Any] = [ 15 | "bcc": [ 16 | "enable": true, 17 | "email": "foo@example.none" 18 | ], 19 | "bypass_list_management": ["enable": true], 20 | "footer": [ 21 | "enable": true, 22 | "text": "Hello World", 23 | "html": "Hello World
" 24 | ], 25 | "sandbox_mode": ["enable": true], 26 | "spam_check": [ 27 | "enable": true, 28 | "threshold": 8 29 | ] 30 | ] 31 | XCTAssertEncodedObject(settings, equals: expected) 32 | } 33 | 34 | func testValidation() { 35 | var noErrors = MailSettings() 36 | XCTAssertNoThrow(try noErrors.validate()) 37 | 38 | noErrors.bcc = BCCSetting(email: "foo@example.none") 39 | XCTAssertNoThrow(try noErrors.validate()) 40 | 41 | noErrors.spamCheck = SpamChecker(threshold: 8) 42 | XCTAssertNoThrow(try noErrors.validate()) 43 | 44 | do { 45 | var bccTest = MailSettings() 46 | bccTest.bcc = BCCSetting(email: "foo") 47 | try bccTest.validate() 48 | } catch let SendGrid.Exception.Mail.malformedEmailAddress(em) { 49 | XCTAssertEqual(em, "foo") 50 | } catch { 51 | XCTFailUnknownError(error) 52 | } 53 | 54 | do { 55 | var spamTest = MailSettings() 56 | spamTest.spamCheck = SpamChecker(threshold: 815) 57 | try spamTest.validate() 58 | } catch let SendGrid.Exception.Mail.thresholdOutOfRange(i) { 59 | XCTAssertEqual(i, 815) 60 | } catch { 61 | XCTFailUnknownError(error) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Mail/SandboxModeTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class SandboxModeTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = SandboxMode 6 | 7 | func testEncoding() { 8 | let on = SandboxMode(enable: true) 9 | XCTAssertEncodedObject(on, equals: ["enable": true]) 10 | 11 | let off = SandboxMode(enable: false) 12 | XCTAssertEncodedObject(off, equals: ["enable": false]) 13 | 14 | let unspecified = SandboxMode() 15 | XCTAssertEncodedObject(unspecified, equals: ["enable": true]) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Mail/SpamCheckerTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class SpamCheckerTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = SpamChecker 6 | 7 | func testEncoding() { 8 | let onSettingMin = SpamChecker(threshold: 4) 9 | XCTAssertEncodedObject(onSettingMin, equals: ["enable": true, "threshold": 4]) 10 | 11 | let onSettingMax = SpamChecker(threshold: 8, url: URL(string: "http://example.none")) 12 | let onSettingMaxExpectations: [String: Any] = [ 13 | "enable": true, 14 | "threshold": 8, 15 | "post_to_url": "http://example.none" 16 | ] 17 | XCTAssertEncodedObject(onSettingMax, equals: onSettingMaxExpectations) 18 | 19 | let offSetting = SpamChecker() 20 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 21 | } 22 | 23 | func testInitialization() { 24 | let basic = SpamChecker(threshold: 4) 25 | XCTAssertTrue(basic.enable) 26 | XCTAssertEqual(basic.threshold, 4) 27 | XCTAssertNil(basic.postURL) 28 | 29 | let url = URL(string: "http://localhost") 30 | let advance = SpamChecker(threshold: 10, url: url) 31 | XCTAssertTrue(advance.enable) 32 | XCTAssertEqual(advance.threshold, 10) 33 | XCTAssertEqual(advance.postURL?.absoluteString, "http://localhost") 34 | 35 | let off = SpamChecker() 36 | XCTAssertFalse(off.enable) 37 | XCTAssertNil(off.threshold) 38 | XCTAssertNil(off.postURL) 39 | } 40 | 41 | func testValidation() { 42 | let good = SpamChecker(threshold: 5) 43 | XCTAssertNoThrow(try good.validate()) 44 | 45 | do { 46 | let over = SpamChecker(threshold: 42) 47 | try over.validate() 48 | XCTFail("Expected an error to be thrown with a threshold over 10, but no errors were raised.") 49 | } catch let SendGrid.Exception.Mail.thresholdOutOfRange(i) { 50 | XCTAssertEqual(i, 42) 51 | } catch { 52 | XCTFailUnknownError(error) 53 | } 54 | 55 | do { 56 | let under = SpamChecker(threshold: 0) 57 | try under.validate() 58 | XCTFail("Expected an error to be thrown with a threshold under 1, but no errors were raised.") 59 | } catch let SendGrid.Exception.Mail.thresholdOutOfRange(i) { 60 | XCTAssertEqual(i, 0) 61 | } catch { 62 | XCTFailUnknownError(error) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Tracking/ClickTrackingTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class ClickTrackingTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = ClickTracking 6 | 7 | func testExample() { 8 | let onSettingMin = ClickTracking(section: .htmlBody) 9 | XCTAssertEncodedObject(onSettingMin, equals: ["enable": true, "enable_text": false]) 10 | 11 | let onSettingMax = ClickTracking(section: .plainTextAndHTMLBodies) 12 | XCTAssertEncodedObject(onSettingMax, equals: ["enable": true, "enable_text": true]) 13 | 14 | let offSetting = ClickTracking(section: .off) 15 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Tracking/GoogleAnalyticsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class GoogleAnalyticsTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = GoogleAnalytics 6 | 7 | func testEncoding() { 8 | let onSettingMin = GoogleAnalytics(source: "test") 9 | XCTAssertEncodedObject(onSettingMin, equals: ["enable": true, "utm_source": "test"]) 10 | 11 | let onSettingMax = GoogleAnalytics( 12 | source: "test_source", 13 | medium: "test_medium", 14 | term: "test_term", 15 | content: "test_content", 16 | campaign: "test_campaign" 17 | ) 18 | let expectation: [String: Any] = [ 19 | "enable": true, 20 | "utm_source": "test_source", 21 | "utm_medium": "test_medium", 22 | "utm_term": "test_term", 23 | "utm_content": "test_content", 24 | "utm_campaign": "test_campaign" 25 | ] 26 | XCTAssertEncodedObject(onSettingMax, equals: expectation) 27 | 28 | let offSetting = GoogleAnalytics() 29 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Tracking/OpenTrackingTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class OpenTrackingTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = OpenTracking 6 | 7 | func testEncoding() { 8 | let onSettingMin = OpenTracking(location: .bottom) 9 | XCTAssertEncodedObject(onSettingMin, equals: ["enable": true]) 10 | 11 | let onSettingMax = OpenTracking(location: .at(tag: "%open%")) 12 | XCTAssertEncodedObject(onSettingMax, equals: ["enable": true, "substitution_tag": "%open%"]) 13 | 14 | let offSetting = OpenTracking(location: .off) 15 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Tracking/SubscriptionTrackingTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class SubscriptionTrackingTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = SubscriptionTracking 6 | 7 | func testEncoding() { 8 | let templateSetting = SubscriptionTracking(plainText: "Unsubscribe: <% %>", html: "<% Unsubscribe %>") 9 | let templateExpectations: [String: Any] = [ 10 | "enable": true, 11 | "text": "Unsubscribe: <% %>", 12 | "html": "<% Unsubscribe %>" 13 | ] 14 | XCTAssertEncodedObject(templateSetting, equals: templateExpectations) 15 | 16 | let subSetting = SubscriptionTracking(substitutionTag: "%unsub%") 17 | XCTAssertEncodedObject(subSetting, equals: ["enable": true, "substitution_tag": "%unsub%"]) 18 | 19 | let offSetting = SubscriptionTracking() 20 | XCTAssertEncodedObject(offSetting, equals: ["enable": false]) 21 | } 22 | 23 | func testValidation() { 24 | let good1 = SubscriptionTracking( 25 | plainText: "Click here to unsubscribe: <% %>.", 26 | html: "<% Click here %> to unsubscribe.
" 27 | ) 28 | XCTAssertNoThrow(try good1.validate()) 29 | 30 | let good2 = SubscriptionTracking() 31 | XCTAssertNoThrow(try good2.validate()) 32 | 33 | do { 34 | let missingPlain = SubscriptionTracking( 35 | plainText: "Click here to unsubscribe", 36 | html: "<% Click here %> to unsubscribe.
" 37 | ) 38 | try missingPlain.validate() 39 | } catch SendGrid.Exception.Mail.missingSubscriptionTrackingTag { 40 | XCTAssertTrue(true) 41 | } catch { 42 | XCTFailUnknownError(error) 43 | } 44 | 45 | do { 46 | let missingHTML = SubscriptionTracking( 47 | plainText: "Click here to unsubscribe: <% %>.", 48 | html: "Click here to unsubscribe.
" 49 | ) 50 | try missingHTML.validate() 51 | } catch SendGrid.Exception.Mail.missingSubscriptionTrackingTag { 52 | XCTAssertTrue(true) 53 | } catch { 54 | XCTFailUnknownError(error) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Mail/Send/Settings/Tracking/TrackingSettingsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class TrackingSettingsTests: XCTestCase, EncodingTester { 5 | typealias EncodableObject = TrackingSettings 6 | 7 | func testEncoding() { 8 | var settings = TrackingSettings() 9 | settings.clickTracking = ClickTracking(section: .htmlBody) 10 | settings.googleAnalytics = GoogleAnalytics(source: "test") 11 | settings.openTracking = OpenTracking(location: .bottom) 12 | settings.subscriptionTracking = SubscriptionTracking(substitutionTag: "%unsub%") 13 | let expected: [String: Any] = [ 14 | "click_tracking": [ 15 | "enable": true, 16 | "enable_text": false 17 | ], 18 | "ganalytics": [ 19 | "enable": true, 20 | "utm_source": "test" 21 | ], 22 | "open_tracking": [ 23 | "enable": true 24 | ], 25 | "subscription_tracking": [ 26 | "enable": true, 27 | "substitution_tag": "%unsub%" 28 | ] 29 | ] 30 | XCTAssertEncodedObject(settings, equals: expected) 31 | } 32 | 33 | func testValidation() { 34 | var plain = TrackingSettings() 35 | XCTAssertNoThrow(try plain.validate()) 36 | 37 | plain.subscriptionTracking = SubscriptionTracking( 38 | plainText: "Click here to unsubscribe: <% %>.", 39 | html: "<% Click here %> to unsubscribe.
" 40 | ) 41 | 42 | XCTAssertNoThrow(try plain.validate()) 43 | 44 | do { 45 | var subTest = TrackingSettings() 46 | subTest.subscriptionTracking = SubscriptionTracking( 47 | plainText: "Click here to unsubscribe.", 48 | html: "<% Click here %> to unsubscribe.
" 49 | ) 50 | try subTest.validate() 51 | } catch SendGrid.Exception.Mail.missingSubscriptionTrackingTag { 52 | XCTAssertTrue(true) 53 | } catch { 54 | XCTFailUnknownError(error) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Stats/RetrieveCategoryStatisticsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveCategoryStatisticsTests: XCTestCase { 5 | func date(day: Int) -> Date { 6 | let formatter = DateFormatter() 7 | formatter.dateFormat = "yyyy-MM-dd" 8 | return formatter.date(from: "2017-09-\(day)")! 9 | } 10 | 11 | func testMinimalInitialization() { 12 | let request = RetrieveCategoryStatistics(startDate: date(day: 20), categories: "Foo") 13 | XCTAssertEqual(request.description, """ 14 | # GET /v3/categories/stats?categories%5B%5D=Foo&start_date=2017-09-20 15 | 16 | + Request (application/json) 17 | 18 | + Headers 19 | 20 | Accept: application/json 21 | Content-Type: application/json 22 | 23 | """) 24 | } 25 | 26 | func testMaxInitialization() { 27 | let request = RetrieveCategoryStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week, categories: "Foo", "Bar") 28 | XCTAssertEqual(request.description, """ 29 | # GET /v3/categories/stats?aggregated_by=week&categories%5B%5D=Foo&categories%5B%5D=Bar&end_date=2017-09-27&start_date=2017-09-20 30 | 31 | + Request (application/json) 32 | 33 | + Headers 34 | 35 | Accept: application/json 36 | Content-Type: application/json 37 | 38 | """) 39 | } 40 | 41 | func testValidation() { 42 | let good = RetrieveCategoryStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week, categories: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") 43 | XCTAssertNoThrow(try good.validate()) 44 | 45 | do { 46 | let under = RetrieveCategoryStatistics(startDate: date(day: 20), categories: []) 47 | try under.validate() 48 | } catch SendGrid.Exception.Statistic.invalidNumberOfCategories { 49 | XCTAssertTrue(true) 50 | } catch { 51 | XCTFailUnknownError(error) 52 | } 53 | 54 | do { 55 | let over = RetrieveCategoryStatistics(startDate: date(day: 20), categories: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") 56 | try over.validate() 57 | } catch SendGrid.Exception.Statistic.invalidNumberOfCategories { 58 | XCTAssertTrue(true) 59 | } catch { 60 | XCTFailUnknownError(error) 61 | } 62 | 63 | do { 64 | let request = RetrieveCategoryStatistics(startDate: date(day: 20), endDate: date(day: 19)) 65 | try request.validate() 66 | XCTFail("Expected a failure to be thrown when the end date is before the start date, but nothing was thrown.") 67 | } catch SendGrid.Exception.Statistic.invalidEndDate { 68 | XCTAssertTrue(true) 69 | } catch { 70 | XCTFailUnknownError(error) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Stats/RetrieveGlobalStatisticsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveGlobalStatisticsTests: XCTestCase { 5 | func date(day: Int) -> Date { 6 | let formatter = DateFormatter() 7 | formatter.dateFormat = "yyyy-MM-dd" 8 | return formatter.date(from: "2017-09-\(day)")! 9 | } 10 | 11 | func testMinimalInitialization() { 12 | let request = RetrieveGlobalStatistics(startDate: date(day: 20)) 13 | XCTAssertEqual(request.description, """ 14 | # GET /v3/stats?start_date=2017-09-20 15 | 16 | + Request (application/json) 17 | 18 | + Headers 19 | 20 | Accept: application/json 21 | Content-Type: application/json 22 | 23 | """) 24 | } 25 | 26 | func testMaxInitialization() { 27 | let request = RetrieveGlobalStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week) 28 | XCTAssertEqual(request.description, """ 29 | # GET /v3/stats?aggregated_by=week&end_date=2017-09-27&start_date=2017-09-20 30 | 31 | + Request (application/json) 32 | 33 | + Headers 34 | 35 | Accept: application/json 36 | Content-Type: application/json 37 | 38 | """) 39 | } 40 | 41 | func testValidation() { 42 | let good = RetrieveGlobalStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week) 43 | XCTAssertNoThrow(try good.validate()) 44 | 45 | do { 46 | let request = RetrieveGlobalStatistics(startDate: date(day: 20), endDate: date(day: 19)) 47 | try request.validate() 48 | XCTFail("Expected a failure to be thrown when the end date is before the start date, but nothing was thrown.") 49 | } catch SendGrid.Exception.Statistic.invalidEndDate { 50 | XCTAssertTrue(true) 51 | } catch { 52 | XCTFailUnknownError(error) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Stats/RetrieveSubuserStatisticsTests.swift: -------------------------------------------------------------------------------- 1 | import SendGrid 2 | import XCTest 3 | 4 | class RetrieveSubuserStatisticsTests: XCTestCase { 5 | func date(day: Int) -> Date { 6 | let formatter = DateFormatter() 7 | formatter.dateFormat = "yyyy-MM-dd" 8 | return formatter.date(from: "2017-09-\(day)")! 9 | } 10 | 11 | func testMinimalInitialization() { 12 | let request = RetrieveSubuserStatistics(startDate: date(day: 20), subusers: "foo") 13 | XCTAssertEqual(request.description, """ 14 | # GET /v3/subusers/stats?start_date=2017-09-20&subusers%5B%5D=foo 15 | 16 | + Request (application/json) 17 | 18 | + Headers 19 | 20 | Accept: application/json 21 | Content-Type: application/json 22 | 23 | """) 24 | 25 | let testSub = Subuser(id: 1, username: "foo", email: "foobar@example.nonet", disabled: false) 26 | let subRequest = RetrieveSubuserStatistics(startDate: date(day: 20), subusers: testSub) 27 | XCTAssertEqual(subRequest.description, """ 28 | # GET /v3/subusers/stats?start_date=2017-09-20&subusers%5B%5D=foo 29 | 30 | + Request (application/json) 31 | 32 | + Headers 33 | 34 | Accept: application/json 35 | Content-Type: application/json 36 | 37 | """) 38 | } 39 | 40 | func testMaxInitialization() { 41 | let request = RetrieveSubuserStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week, subusers: "Foo", "Bar") 42 | XCTAssertEqual(request.description, """ 43 | # GET /v3/subusers/stats?aggregated_by=week&end_date=2017-09-27&start_date=2017-09-20&subusers%5B%5D=Foo&subusers%5B%5D=Bar 44 | 45 | + Request (application/json) 46 | 47 | + Headers 48 | 49 | Accept: application/json 50 | Content-Type: application/json 51 | 52 | """) 53 | } 54 | 55 | func testValidation() { 56 | let good = RetrieveSubuserStatistics(startDate: date(day: 20), endDate: date(day: 27), aggregatedBy: .week, subusers: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") 57 | XCTAssertNoThrow(try good.validate()) 58 | 59 | do { 60 | let under = RetrieveSubuserStatistics(startDate: date(day: 20), subusers: [String]()) 61 | try under.validate() 62 | } catch SendGrid.Exception.Statistic.invalidNumberOfSubusers { 63 | XCTAssertTrue(true) 64 | } catch { 65 | XCTFailUnknownError(error) 66 | } 67 | 68 | do { 69 | let over = RetrieveSubuserStatistics(startDate: date(day: 20), subusers: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven") 70 | try over.validate() 71 | } catch SendGrid.Exception.Statistic.invalidNumberOfSubusers { 72 | XCTAssertTrue(true) 73 | } catch { 74 | XCTFailUnknownError(error) 75 | } 76 | 77 | do { 78 | let request = RetrieveSubuserStatistics(startDate: date(day: 20), endDate: date(day: 19), subusers: "one", "two", "three") 79 | try request.validate() 80 | XCTFail("Expected a failure to be thrown when the end date is before the start date, but nothing was thrown.") 81 | } catch SendGrid.Exception.Statistic.invalidEndDate { 82 | XCTAssertTrue(true) 83 | } catch { 84 | XCTFailUnknownError(error) 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Subuser/RetrieveSubusersTests.swift: -------------------------------------------------------------------------------- 1 | import SendGrid 2 | import XCTest 3 | 4 | class RetrieveSubusersTests: XCTestCase { 5 | func testInitialization() { 6 | let min = RetrieveSubusers() 7 | XCTAssertEqual(min.description, """ 8 | # GET /v3/subusers 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let max = RetrieveSubusers(page: Page(limit: 1, offset: 2), username: "foo") 20 | XCTAssertEqual(max.description, """ 21 | # GET /v3/subusers?limit=1&offset=2&username=foo 22 | 23 | + Request (application/json) 24 | 25 | + Headers 26 | 27 | Accept: application/json 28 | Content-Type: application/json 29 | 30 | """) 31 | } 32 | 33 | func testValidation() { 34 | let goodMin = RetrieveSubusers() 35 | XCTAssertNoThrow(try goodMin.validate()) 36 | 37 | let goodMax = RetrieveSubusers(page: Page(limit: 500, offset: 0), username: "foo") 38 | XCTAssertNoThrow(try goodMax.validate()) 39 | 40 | do { 41 | let under = RetrieveSubusers(page: Page(limit: 0, offset: 0)) 42 | try under.validate() 43 | } catch SendGrid.Exception.Global.limitOutOfRange(let i, _) { 44 | XCTAssertEqual(i, 0) 45 | } catch { 46 | XCTFailUnknownError(error) 47 | } 48 | 49 | do { 50 | let over = RetrieveSubusers(page: Page(limit: 501, offset: 0)) 51 | try over.validate() 52 | } catch SendGrid.Exception.Global.limitOutOfRange(let i, _) { 53 | XCTAssertEqual(i, 501) 54 | } catch { 55 | XCTFailUnknownError(error) 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Blocks/DeleteBlocksTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class DeleteBlocksTests: XCTestCase { 5 | func testInitializer() { 6 | let request = DeleteBlocks(emails: "foo@example.none", "bar@example.none") 7 | XCTAssertEqual(request.description, """ 8 | # DELETE /v3/suppression/blocks 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | + Body 18 | 19 | {"emails":["foo@example.none","bar@example.none"]} 20 | 21 | """) 22 | } 23 | 24 | func testDeleteAll() { 25 | let request = DeleteBlocks.all 26 | XCTAssertEqual(request.description, """ 27 | # DELETE /v3/suppression/blocks 28 | 29 | + Request (application/json) 30 | 31 | + Headers 32 | 33 | Accept: application/json 34 | Content-Type: application/json 35 | 36 | + Body 37 | 38 | {"delete_all":true} 39 | 40 | """) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Blocks/RetrieveBlocks.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveBlocksTests: XCTestCase { 5 | func testGetAllInitialization() { 6 | let minRequest = RetrieveBlocks() 7 | XCTAssertEqual(minRequest.description, """ 8 | # GET /v3/suppression/blocks 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let start = Date(timeIntervalSince1970: 15) 20 | let end = Date(timeIntervalSince1970: 16) 21 | let maxRequest = RetrieveBlocks(start: start, end: end, page: Page(limit: 4, offset: 8)) 22 | XCTAssertEqual(maxRequest.description, """ 23 | # GET /v3/suppression/blocks?end_time=16&limit=4&offset=8&start_time=15 24 | 25 | + Request (application/json) 26 | 27 | + Headers 28 | 29 | Accept: application/json 30 | Content-Type: application/json 31 | 32 | """) 33 | } 34 | 35 | func testEmailSpecificInitializer() { 36 | let request = RetrieveBlocks(email: "foo@example.none") 37 | XCTAssertEqual(request.description, """ 38 | # GET /v3/suppression/blocks/foo@example.none 39 | 40 | + Request (application/json) 41 | 42 | + Headers 43 | 44 | Accept: application/json 45 | Content-Type: application/json 46 | 47 | """) 48 | } 49 | 50 | func testValidation() { 51 | do { 52 | let request = RetrieveBlocks(page: Page(limit: 501, offset: 0)) 53 | try request.validate() 54 | XCTFail("Expected an error to be thrown when the limit is above 500, but no error was thrown.") 55 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 56 | XCTAssertEqual(i, 501) 57 | XCTAssertEqual(range, 1...500) 58 | } catch { 59 | XCTFailUnknownError(error) 60 | } 61 | 62 | do { 63 | let request = RetrieveBlocks(page: Page(limit: 0, offset: 0)) 64 | try request.validate() 65 | XCTFail("Expected an error to be thrown when the limit is below 1, but no error was thrown.") 66 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 67 | XCTAssertEqual(i, 0) 68 | XCTAssertEqual(range, 1...500) 69 | } catch { 70 | XCTFailUnknownError(error) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Bounces/DeleteBouncesTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class DeleteBouncesTests: XCTestCase { 5 | func testInitializer() { 6 | func assert(request: DeleteBounces) { 7 | XCTAssertEqual(request.description, """ 8 | # DELETE /v3/suppression/bounces 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | + Body 18 | 19 | {"emails":["foo@example.none","bar@example.none"]} 20 | 21 | """) 22 | } 23 | 24 | let emails = DeleteBounces(emails: "foo@example.none", "bar@example.none") 25 | assert(request: emails) 26 | 27 | let fooBounce = Bounce(email: "foo@example.none", created: Date(), reason: "Because", status: "4.8.15") 28 | let barBounce = Bounce(email: "bar@example.none", created: Date(), reason: "Because", status: "16.23.42") 29 | let events = DeleteBounces(events: fooBounce, barBounce) 30 | assert(request: events) 31 | } 32 | 33 | func testDeleteAll() { 34 | let request = DeleteBounces.all 35 | XCTAssertEqual(request.description, """ 36 | # DELETE /v3/suppression/bounces 37 | 38 | + Request (application/json) 39 | 40 | + Headers 41 | 42 | Accept: application/json 43 | Content-Type: application/json 44 | 45 | + Body 46 | 47 | {"delete_all":true} 48 | 49 | """) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Bounces/RetrieveBouncesTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveBouncesTests: XCTestCase { 5 | func testGetAllInitialization() { 6 | let minRequest = RetrieveBounces() 7 | XCTAssertEqual(minRequest.description, """ 8 | # GET /v3/suppression/bounces 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let start = Date(timeIntervalSince1970: 15) 20 | let end = Date(timeIntervalSince1970: 16) 21 | let maxRequest = RetrieveBounces(start: start, end: end, page: Page(limit: 4, offset: 8)) 22 | XCTAssertEqual(maxRequest.description, """ 23 | # GET /v3/suppression/bounces?end_time=16&limit=4&offset=8&start_time=15 24 | 25 | + Request (application/json) 26 | 27 | + Headers 28 | 29 | Accept: application/json 30 | Content-Type: application/json 31 | 32 | """) 33 | } 34 | 35 | func testEmailSpecificInitializer() { 36 | let request = RetrieveBounces(email: "foo@example.none") 37 | XCTAssertEqual(request.description, """ 38 | # GET /v3/suppression/bounces/foo@example.none 39 | 40 | + Request (application/json) 41 | 42 | + Headers 43 | 44 | Accept: application/json 45 | Content-Type: application/json 46 | 47 | """) 48 | } 49 | 50 | func testValidation() { 51 | let good = RetrieveBounces(page: Page(limit: 1, offset: 1)) 52 | XCTAssertNoThrow(try good.validate()) 53 | 54 | do { 55 | let request = RetrieveBounces(page: Page(limit: 0, offset: 0)) 56 | try request.validate() 57 | XCTFail("Expected an error to be thrown when the limit is below 1, but no error was thrown.") 58 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 59 | XCTAssertEqual(i, 0) 60 | XCTAssertEqual(range, 1...500) 61 | } catch { 62 | XCTFailUnknownError(error) 63 | } 64 | 65 | do { 66 | let request = RetrieveBounces(page: Page(limit: 501, offset: 0)) 67 | try request.validate() 68 | XCTFail("Expected an error to be thrown when the limit is above 500, but no error was thrown.") 69 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 70 | XCTAssertEqual(i, 501) 71 | XCTAssertEqual(range, 1...500) 72 | } catch { 73 | XCTFailUnknownError(error) 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Global Unsubscribes/AddGlobalUnsubscribesTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class AddGlobalUnsubscribesTests: XCTestCase { 5 | func testInitialization() { 6 | func assert(request: AddGlobalUnsubscribes) { 7 | XCTAssertEqual(request.description, """ 8 | # POST /v3/asm/suppressions/global 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | + Body 18 | 19 | {"recipient_emails":["foo@example.none","bar@example.none"]} 20 | 21 | """) 22 | } 23 | 24 | let emails = AddGlobalUnsubscribes(emails: "foo@example.none", "bar@example.none") 25 | assert(request: emails) 26 | 27 | let addresses = AddGlobalUnsubscribes(addresses: Address(email: "foo@example.none"), Address(email: "bar@example.none")) 28 | assert(request: addresses) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Global Unsubscribes/DeleteGlobalUnsubscribeTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class DeleteGlobalUnsubscribeTests: XCTestCase { 5 | func testInitializer() { 6 | func assert(request: DeleteGlobalUnsubscribe) { 7 | XCTAssertEqual(request.description, """ 8 | # DELETE /v3/asm/suppressions/global/foo@example.none 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | } 19 | 20 | let email = DeleteGlobalUnsubscribe(email: "foo@example.none") 21 | assert(request: email) 22 | 23 | let event = GlobalUnsubscribe(email: "foo@example.none", created: Date()) 24 | let request = DeleteGlobalUnsubscribe(event: event) 25 | assert(request: request) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Global Unsubscribes/RetrieveGlobalUnsubscribesTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveGlobalUnsubscribesTests: XCTestCase { 5 | func testGetAllInitialization() { 6 | let minRequest = RetrieveGlobalUnsubscribes() 7 | XCTAssertEqual(minRequest.description, """ 8 | # GET /v3/suppression/unsubscribes 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let start = Date(timeIntervalSince1970: 15) 20 | let end = Date(timeIntervalSince1970: 16) 21 | let maxRequest = RetrieveGlobalUnsubscribes(start: start, end: end, page: Page(limit: 4, offset: 8)) 22 | XCTAssertEqual(maxRequest.description, """ 23 | # GET /v3/suppression/unsubscribes?end_time=16&limit=4&offset=8&start_time=15 24 | 25 | + Request (application/json) 26 | 27 | + Headers 28 | 29 | Accept: application/json 30 | Content-Type: application/json 31 | 32 | """) 33 | } 34 | 35 | func testEmailSpecificInitializer() { 36 | let request = RetrieveGlobalUnsubscribes(email: "foo@example.none") 37 | XCTAssertEqual(request.description, """ 38 | # GET /v3/suppression/unsubscribes/foo@example.none 39 | 40 | + Request (application/json) 41 | 42 | + Headers 43 | 44 | Accept: application/json 45 | Content-Type: application/json 46 | 47 | """) 48 | } 49 | 50 | func testValidation() { 51 | do { 52 | let request = RetrieveGlobalUnsubscribes(page: Page(limit: 0, offset: 0)) 53 | try request.validate() 54 | XCTFail("Expected an error to be thrown when the limit is below 1, but no error was thrown.") 55 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 56 | XCTAssertEqual(i, 0) 57 | XCTAssertEqual(range, 1...500) 58 | } catch { 59 | XCTFailUnknownError(error) 60 | } 61 | 62 | do { 63 | let request = RetrieveGlobalUnsubscribes(page: Page(limit: 501, offset: 0)) 64 | try request.validate() 65 | XCTFail("Expected an error to be thrown when the limit is above 500, but no error was thrown.") 66 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 67 | XCTAssertEqual(i, 501) 68 | XCTAssertEqual(range, 1...500) 69 | } catch { 70 | XCTFailUnknownError(error) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Invalid Emails/DeleteInvalidEmailsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class DeleteInvalidEmailsTests: XCTestCase { 5 | func testInitializer() { 6 | let request = DeleteInvalidEmails(emails: "foo@example.none", "bar@example.none") 7 | XCTAssertEqual(request.description, """ 8 | # DELETE /v3/suppression/invalid_emails 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | + Body 18 | 19 | {"emails":["foo@example.none","bar@example.none"]} 20 | 21 | """) 22 | } 23 | 24 | func testDeleteAll() { 25 | let request = DeleteInvalidEmails.all 26 | XCTAssertEqual(request.description, """ 27 | # DELETE /v3/suppression/invalid_emails 28 | 29 | + Request (application/json) 30 | 31 | + Headers 32 | 33 | Accept: application/json 34 | Content-Type: application/json 35 | 36 | + Body 37 | 38 | {"delete_all":true} 39 | 40 | """) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Invalid Emails/RetrieveInvalidEmailsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveInvalidEmailsTests: XCTestCase { 5 | func testGetAllInitialization() { 6 | let minRequest = RetrieveInvalidEmails() 7 | XCTAssertEqual(minRequest.description, """ 8 | # GET /v3/suppression/invalid_emails 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let start = Date(timeIntervalSince1970: 15) 20 | let end = Date(timeIntervalSince1970: 16) 21 | let maxRequest = RetrieveInvalidEmails(start: start, end: end, page: Page(limit: 4, offset: 8)) 22 | XCTAssertEqual(maxRequest.description, """ 23 | # GET /v3/suppression/invalid_emails?end_time=16&limit=4&offset=8&start_time=15 24 | 25 | + Request (application/json) 26 | 27 | + Headers 28 | 29 | Accept: application/json 30 | Content-Type: application/json 31 | 32 | """) 33 | } 34 | 35 | func testEmailSpecificInitializer() { 36 | let request = RetrieveInvalidEmails(email: "foo@example.none") 37 | XCTAssertEqual(request.description, """ 38 | # GET /v3/suppression/invalid_emails/foo@example.none 39 | 40 | + Request (application/json) 41 | 42 | + Headers 43 | 44 | Accept: application/json 45 | Content-Type: application/json 46 | 47 | """) 48 | } 49 | 50 | func testValidation() { 51 | do { 52 | let request = RetrieveInvalidEmails(page: Page(limit: 0, offset: 0)) 53 | try request.validate() 54 | XCTFail("Expected an error to be thrown when the limit is below 1, but no error was thrown.") 55 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 56 | XCTAssertEqual(i, 0) 57 | XCTAssertEqual(range, 1...500) 58 | } catch { 59 | XCTFailUnknownError(error) 60 | } 61 | 62 | do { 63 | let request = RetrieveInvalidEmails(page: Page(limit: 501, offset: 0)) 64 | try request.validate() 65 | XCTFail("Expected an error to be thrown when the limit is above 500, but no error was thrown.") 66 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 67 | XCTAssertEqual(i, 501) 68 | XCTAssertEqual(range, 1...500) 69 | } catch { 70 | XCTFailUnknownError(error) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Spam Reports/DeleteSpamReportsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class DeleteSpamReportsTests: XCTestCase { 5 | func testInitializer() { 6 | let request = DeleteSpamReports(emails: "foo@example.none", "bar@example.none") 7 | XCTAssertEqual(request.description, """ 8 | # DELETE /v3/suppression/spam_reports 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | + Body 18 | 19 | {"emails":["foo@example.none","bar@example.none"]} 20 | 21 | """) 22 | } 23 | 24 | func testDeleteAll() { 25 | let request = DeleteSpamReports.all 26 | XCTAssertEqual(request.description, """ 27 | # DELETE /v3/suppression/spam_reports 28 | 29 | + Request (application/json) 30 | 31 | + Headers 32 | 33 | Accept: application/json 34 | Content-Type: application/json 35 | 36 | + Body 37 | 38 | {"delete_all":true} 39 | 40 | """) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/Spam Reports/RetrieveSpamReportsTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class RetrieveSpamReportsTests: XCTestCase { 5 | func testGetAllInitialization() { 6 | let minRequest = RetrieveSpamReports() 7 | XCTAssertEqual(minRequest.description, """ 8 | # GET /v3/suppression/spam_reports 9 | 10 | + Request (application/json) 11 | 12 | + Headers 13 | 14 | Accept: application/json 15 | Content-Type: application/json 16 | 17 | """) 18 | 19 | let start = Date(timeIntervalSince1970: 15) 20 | let end = Date(timeIntervalSince1970: 16) 21 | let maxRequest = RetrieveSpamReports(start: start, end: end, page: Page(limit: 4, offset: 8)) 22 | XCTAssertEqual(maxRequest.description, """ 23 | # GET /v3/suppression/spam_reports?end_time=16&limit=4&offset=8&start_time=15 24 | 25 | + Request (application/json) 26 | 27 | + Headers 28 | 29 | Accept: application/json 30 | Content-Type: application/json 31 | 32 | """) 33 | } 34 | 35 | func testEmailSpecificInitializer() { 36 | let request = RetrieveSpamReports(email: "foo@example.none") 37 | XCTAssertEqual(request.description, """ 38 | # GET /v3/suppression/spam_reports/foo@example.none 39 | 40 | + Request (application/json) 41 | 42 | + Headers 43 | 44 | Accept: application/json 45 | Content-Type: application/json 46 | 47 | """) 48 | } 49 | 50 | func testValidation() { 51 | do { 52 | let request = RetrieveSpamReports(page: Page(limit: 0, offset: 0)) 53 | try request.validate() 54 | XCTFail("Expected an error to be thrown when the limit is below 1, but no error was thrown.") 55 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 56 | XCTAssertEqual(i, 0) 57 | XCTAssertEqual(range, 1...500) 58 | } catch { 59 | XCTFailUnknownError(error) 60 | } 61 | 62 | do { 63 | let request = RetrieveSpamReports(page: Page(limit: 501, offset: 0)) 64 | try request.validate() 65 | XCTFail("Expected an error to be thrown when the limit is above 500, but no error was thrown.") 66 | } catch let SendGrid.Exception.Global.limitOutOfRange(i, range) { 67 | XCTAssertEqual(i, 501) 68 | XCTAssertEqual(range, 1...500) 69 | } catch { 70 | XCTFailUnknownError(error) 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/SendGridTests/API/V3/Suppression/SuppressionListDeleterTests.swift: -------------------------------------------------------------------------------- 1 | @testable import SendGrid 2 | import XCTest 3 | 4 | class SuppressionListDeleterTests: XCTestCase { 5 | func testInitialization() { 6 | let deleteAllOn = SuppressionListDeleter