Skip to content

Commit 37b64d2

Browse files
refactor: add more examples for cursor rules and move dev descriptions to dev.yml
1 parent 5536a81 commit 37b64d2

File tree

3 files changed

+74
-58
lines changed

3 files changed

+74
-58
lines changed

.cursor/rules/swift-development.mdc

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,26 @@ alwaysApply: true
2121
3. **Test Issues** → `dev test` - Checks for failing tests
2222

2323
### Available dev commands:
24-
```bash
25-
# Code Quality
26-
dev lint # Check format & lint issues (alias: dev style)
27-
dev fix # auto fixes formatting and linting issues
28-
29-
# Building
30-
dev build packages # Build ShopifyCheckoutSheetKit & ShopifyAcceleratedCheckouts
31-
dev build samples # Build sample apps
32-
33-
# Testing
34-
dev test packages # Test the packages
35-
dev test samples # Test sample apps
36-
37-
# Apollo/GraphQL
38-
dev apollo download_schema # Download GraphQL schema
39-
dev apollo codegen # Generate Apollo client code
24+
**See `dev.yml` in project root for complete list of commands and descriptions.**
25+
26+
Key commands for verification:
27+
- `dev lint` (alias: `dev style`) - Check format & lint issues
28+
- `dev fix` - Auto-fix formatting and linting issues
29+
- `dev build packages` - Build both packages
30+
- `dev test packages` - Run all tests
31+
32+
## Concurrency Best Practices
33+
34+
### DO: Use actors for thread-safe shared state
35+
```swift
36+
actor QueryCache {
37+
private var cache: [String: Any] = [:]
38+
private var inflightRequests: [String: Any] = [:]
39+
40+
func loadCached<T>(...) async throws -> T {
41+
// Safe concurrent access to shared state
42+
}
43+
}
4044
```
4145

4246
## Workflow Best Practices

.cursor/rules/swift-test.mdc

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ alwaysApply: true
1111
### DO:
1212
- Create separate test methods for each test case
1313
- Use `guard` statements with `XCTFail` for unwrapping optionals
14-
- Write focused tests that test one thing at a time
15-
- Use descriptive test method names that explain what is being tested
16-
- Catch only one error type per test
17-
- Create separate test methods instead of conditional logic
18-
19-
### DON'T:
20-
- Use typed catches when testing throwing expressions
21-
- Delete and recreate test files when debugging
22-
- Add boilerplate comments like "// Given", "// When", "// Then"
23-
24-
## Code Examples
25-
26-
### ✅ CORRECT: Unwrapping optionals
2714
```swift
2815
func testSomething() {
2916
guard let result = someOptionalValue else {
@@ -33,36 +20,61 @@ func testSomething() {
3320
XCTAssertEqual(result, expectedValue)
3421
}
3522
```
23+
- Write focused tests that test one thing at a time
24+
- Use descriptive test method names in the format `test_<methodName>_<withCircumstances>_<shouldExpectation>`
25+
```
26+
func test_canTransition_fromAppleSheetPresentedState_shouldAllowPaymentAuthorizationAndInterruptAndCompleted()
27+
func test_ensureCurrencyNotChanged_withNoInitialCurrency_shouldNotThrow()
28+
```
3629

37-
### ❌ INCORRECT: Conditional test logic
38-
```swift
39-
// DON'T DO THIS
40-
func testSomething() {
41-
if condition {
42-
XCTAssertTrue(something)
43-
} else {
44-
XCTAssertFalse(something)
30+
- If a function may throw multiple types of errors, write multiple tests to capture them in isolation
31+
```
32+
func throwingFunction() {
33+
if someCondition {
34+
throw Error.foo
35+
} else
36+
throw Error.bar
37+
}
38+
39+
func test_throwingFunction_whenSomeConditionTrue_shouldThrowFoo() {
40+
do {
41+
_ = try await storefront.createCart()
42+
XCTFail("Expected error to be thrown")
43+
} catch {
44+
guard case let error = Error.foo else {
45+
XCTFail("Expected .foo")
46+
}
4547
}
46-
}
48+
}
49+
func test_throwingFunction_whenSomeConditionTrue_shouldThrowBar(){
50+
do {
51+
_ = try await storefront.createCart()
52+
XCTFail("Expected error to be thrown")
53+
} catch {
54+
guard case let error = Error.foo else {
55+
XCTFail("Expected .foo")
56+
}
57+
}
58+
}
4759
```
4860

49-
### ✅ CORRECT: Separate test methods
50-
```swift
51-
func testSomething_whenConditionTrue() {
52-
// Test for true condition
53-
}
61+
## Code Examples
5462

55-
func testSomething_whenConditionFalse() {
56-
// Test for false condition
63+
### ✅ CORRECT: Unwrapping optionals
64+
```swift
65+
func testSomething() {
66+
guard let result = someOptionalValue else {
67+
XCTFail("Expected non-nil value")
68+
return
69+
}
70+
XCTAssertEqual(result, expectedValue)
5771
}
5872
```
5973

60-
## Error Testing
61-
62-
When testing throwing functions:
63-
- Test only ONE error type per test method
64-
- Avoid typed catch blocks that check for specific error types
65-
- Let unhandled errors fail the test naturally
74+
### DON'T:
75+
- Use typed catches when testing throwing expressions
76+
- Delete and recreate test files when debugging
77+
- Add boilerplate comments like "// Given", "// When", "// Then"
6678

6779
## Comments
6880

dev.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@ check:
3030
commands:
3131
lint:
3232
aliases: [style]
33-
desc: Check Format & Lint issues
33+
desc: Check format and lint issues across all Swift files using SwiftLint and SwiftFormat
3434
run: scripts/lint
3535
fix:
36-
desc: Autofix Format & Lint issues
36+
desc: Automatically fix format and lint issues where possible
3737
run: scripts/lint fix
3838
build:
3939
subcommands:
4040
packages:
41-
desc: Build the Package
41+
desc: Build both ShopifyCheckoutSheetKit and ShopifyAcceleratedCheckouts packages
4242
run: |
4343
./scripts/xcode_run build ShopifyCheckoutSheetKit
4444
./scripts/xcode_run build ShopifyAcceleratedCheckouts
4545
samples:
46-
desc: Build the Samples
46+
desc: Build all sample applications to verify integration
4747
run: ./scripts/build_samples
4848
test:
4949
subcommands:
5050
packages:
51-
desc: Test the Packages
51+
desc: Run all unit and integration tests for the packages
5252
run: |
5353
./scripts/xcode_run test ShopifyCheckoutSheetKit-Package
5454
samples:
55-
desc: Test the Samples
55+
desc: Run tests for sample applications
5656
run: ./scripts/test_samples
5757

5858
apollo:
@@ -68,7 +68,7 @@ commands:
6868
rover graph introspect https://$DOMAIN/api/$API_VERSION/graphql --header="X-Shopify-Storefront-Access-Token: $TOKEN" --output schema.$API_VERSION.graphqls
6969
7070
codegen:
71-
desc: Generate Apollo Client
71+
desc: Generate Apollo Client models and request functions for sample app
7272
run: |
7373
cd ./Samples/ShopifyAcceleratedCheckoutsApp/
7474
./apollo-ios-cli generate

0 commit comments

Comments
 (0)