-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt
swift-format
, update to SendGridKit v3 and Swift Testing
- Loading branch information
1 parent
66be154
commit 9f6f453
Showing
10 changed files
with
80 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
version: 1 | ||
builder: | ||
configs: | ||
- documentation_targets: [SendGrid] | ||
- documentation_targets: [SendGrid] | ||
swift_version: 6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ extension Request { | |
public var sendgrid: Application.Sendgrid { | ||
.init(application: self.application) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Vapor | ||
|
||
let isLoggingConfigured: Bool = { | ||
LoggingSystem.bootstrap { label in | ||
var handler = StreamLogHandler.standardOutput(label: label) | ||
handler.logLevel = .debug | ||
return handler | ||
} | ||
return true | ||
}() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Testing | ||
import Vapor | ||
|
||
func withApp(_ body: (Application) async throws -> Void) async throws { | ||
let app = try await Application.make(.testing) | ||
try #require(isLoggingConfigured == true) | ||
try await body(app) | ||
try await app.asyncShutdown() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,45 @@ | ||
import XCTVapor | ||
import SendGrid | ||
import Testing | ||
import XCTVapor | ||
|
||
class SendGridTests: XCTestCase { | ||
var app: Application! | ||
|
||
override func setUp() async throws { | ||
self.app = try await Application.make(.testing) | ||
} | ||
|
||
override func tearDown() async throws { | ||
try await app.asyncShutdown() | ||
} | ||
|
||
func testApplication() async throws { | ||
// TODO: Replace from addresses and to addresses | ||
let email = SendGridEmail( | ||
personalizations: [Personalization(to: ["TO-ADDRESS"])], | ||
from: "FROM-ADDRESS", | ||
subject: "Test Email", | ||
content: ["This email was sent using SendGridKit!"] | ||
) | ||
|
||
do { | ||
try await app.sendgrid.client.send(email: email) | ||
} catch {} | ||
} | ||
|
||
func testRequest() async throws { | ||
app.get("test") { req async throws -> Response in | ||
struct SendGridTests { | ||
@Test func application() async throws { | ||
try await withApp { app in | ||
// TODO: Replace from addresses and to addresses | ||
let email = SendGridEmail( | ||
personalizations: [Personalization(to: ["TO-ADDRESS"])], | ||
from: "FROM-ADDRESS", | ||
subject: "Test Email", | ||
content: ["This email was sent using SendGridKit!"] | ||
) | ||
try await req.sendgrid.client.send(email: email) | ||
return Response(status: .ok) | ||
|
||
try await withKnownIssue { | ||
try await app.sendgrid.client.send(email: email) | ||
} when: { | ||
// TODO: Replace with `false` when you have a valid API key | ||
true | ||
} | ||
} | ||
} | ||
|
||
@Test func request() async throws { | ||
try await withApp { app in | ||
app.get("test") { req async throws -> Response in | ||
// TODO: Replace from addresses and to addresses | ||
let email = SendGridEmail( | ||
personalizations: [Personalization(to: ["TO-ADDRESS"])], | ||
from: "FROM-ADDRESS", | ||
subject: "Test Email", | ||
content: ["This email was sent using SendGridKit!"] | ||
) | ||
try await req.sendgrid.client.send(email: email) | ||
return Response(status: .ok) | ||
} | ||
|
||
try await app.test(.GET, "test") { res async throws in | ||
XCTAssertEqual(res.status, .internalServerError) | ||
try await app.test(.GET, "test") { res async throws in | ||
// TODO: Replace with `.ok` when you have a valid API key | ||
#expect(res.status == .internalServerError) | ||
} | ||
} | ||
} | ||
} |