|
1 |
| -import XCTest |
2 |
| -@testable import IndiePitcherSwift |
3 | 1 | import AsyncHTTPClient
|
4 | 2 | import Nimble
|
| 3 | +import XCTest |
| 4 | + |
| 5 | +@testable import IndiePitcherSwift |
5 | 6 |
|
6 | 7 | final class IndiePitcherSwiftTests: XCTestCase {
|
7 |
| - |
| 8 | + |
8 | 9 | var indiePitcher: IndiePitcher!
|
9 |
| - |
| 10 | + |
10 | 11 | override func setUp() async throws {
|
11 | 12 | indiePitcher = IndiePitcher(apiKey: IP_SECRET_API_KEY)
|
12 | 13 | }
|
13 |
| - |
| 14 | + |
14 | 15 | override func tearDown() async throws {
|
15 | 16 | // work around API rate limiting
|
16 | 17 | try await Task.sleep(for: .seconds(1))
|
17 | 18 | }
|
18 |
| - |
| 19 | + |
19 | 20 | func testThrowRequestError() async {
|
20 | 21 | let indiePitcherx = IndiePitcher(apiKey: "fake")
|
21 |
| - await expect({try await indiePitcherx.listMailingLists()}) |
| 22 | + await expect({ try await indiePitcherx.listMailingLists() }) |
22 | 23 | .to(throwError(IndiePitcherRequestError(statusCode: 401, reason: "Unauthorized")))
|
23 | 24 | }
|
24 |
| - |
| 25 | + |
25 | 26 | func testSendTransactionalEmailMarkdown() async throws {
|
26 |
| - |
27 |
| - try await indiePitcher .sendEmail(data : .init (to : "[email protected]", |
28 |
| - subject: "Test email from IP Swift SDK unit tests", |
29 |
| - body: "This is a test body that supports **markdown**.", |
30 |
| - bodyFormat: .markdown)) |
| 27 | + |
| 28 | + try await indiePitcher.sendEmail( |
| 29 | + data: .init( |
| 30 | + |
| 31 | + subject: "Test email from IP Swift SDK unit tests", |
| 32 | + body: "This is a test body that supports **markdown**.", |
| 33 | + bodyFormat: .markdown)) |
31 | 34 | }
|
32 |
| - |
| 35 | + |
33 | 36 | func testGetMailingLists() async throws {
|
34 | 37 | let listsResponse = try await indiePitcher.listMailingLists()
|
35 | 38 | expect(listsResponse.metadata.total) == 3
|
36 | 39 | expect(listsResponse.data.count) == 3
|
37 | 40 | }
|
38 |
| - |
| 41 | + |
39 | 42 | func testSendMarketingEmailToList() async throws {
|
40 |
| - try await indiePitcher.sendEmailToMailingList(data: .init(subject: "Test marketing email from IP Swift SDK unit tests", |
41 |
| - body: "This is a test body of a marketing email that supports **markdown**.", |
42 |
| - bodyFormat: .markdown, |
43 |
| - list: "integration-tests")) |
| 43 | + try await indiePitcher.sendEmailToMailingList( |
| 44 | + data: .init( |
| 45 | + subject: "Test marketing email from IP Swift SDK unit tests", |
| 46 | + body: "This is a test body of a marketing email that supports **markdown**.", |
| 47 | + bodyFormat: .markdown, |
| 48 | + list: "integration-tests")) |
44 | 49 | }
|
45 |
| - |
| 50 | + |
46 | 51 | func testSendEmailToContact() async throws {
|
47 |
| - try await indiePitcher .sendEmailToContact(data : .init (contactEmail : "[email protected]", |
48 |
| - subject: "Test personalized contact email from IP Swift SDK unit tests", |
49 |
| - body: "This is a test body of a personalized transactional email that supports **markdown**.", |
50 |
| - bodyFormat: .markdown, |
51 |
| - list: "integration-tests", |
52 |
| - delaySeconds: 60)) |
| 52 | + try await indiePitcher.sendEmailToContact( |
| 53 | + data: .init( |
| 54 | + contactEmail : "[email protected]", |
| 55 | + subject: "Test personalized contact email from IP Swift SDK unit tests", |
| 56 | + body: |
| 57 | + "This is a test body of a personalized transactional email that supports **markdown**.", |
| 58 | + bodyFormat: .markdown, |
| 59 | + list: "integration-tests", |
| 60 | + delaySeconds: 60)) |
53 | 61 | }
|
54 |
| - |
| 62 | + |
55 | 63 | func testContactManagement() async throws {
|
56 | 64 |
|
57 |
| - try await indiePitcher.addContact(contact: .init(email: email, |
58 |
| - subscribedToLists: ["test_list_1", "test_list_2"])) |
| 65 | + try await indiePitcher.addContact( |
| 66 | + contact: .init( |
| 67 | + email: email, |
| 68 | + subscribedToLists: ["test_list_1", "test_list_2"])) |
| 69 | + |
| 70 | + let contact = try await indiePitcher.findContact(email: email).data |
| 71 | + expect(contact.email) == email |
| 72 | + expect(contact.subscribedToLists) == ["test_list_1", "test_list_2"] |
59 | 73 |
|
60 | 74 | try await indiePitcher.deleteContact(email: email)
|
61 | 75 | }
|
62 |
| - |
| 76 | + |
63 | 77 | func testAddMultipleContacts() async throws {
|
64 |
| - |
65 |
| - try await indiePitcher .addContacts(contacts : [.init (email : "[email protected]"), .init (email : "[email protected]")]) |
| 78 | + |
| 79 | + try await indiePitcher.addContacts(contacts: [ |
| 80 | + .init (email : "[email protected]"), .init (email : "[email protected]"), |
| 81 | + ]) |
66 | 82 | try await indiePitcher .deleteContact(email : "[email protected]")
|
67 | 83 | try await indiePitcher .deleteContact(email : "[email protected]")
|
68 | 84 | }
|
69 |
| - |
| 85 | + |
70 | 86 | func testCreatePortalSession() async throws {
|
71 |
| - _ = try await indiePitcher .createMailingListsPortalSession(contactEmail : "[email protected]", returnURL : .init (string : "https://indiepitcher.com")! ) |
| 87 | + _ = try await indiePitcher.createMailingListsPortalSession( |
| 88 | + contactEmail : "[email protected]", |
| 89 | + returnURL: .init(string: "https://indiepitcher.com")!) |
72 | 90 | }
|
73 | 91 | }
|
0 commit comments