Skip to content

Commit 4da3da7

Browse files
committed
chore(tests): Added tests for FE and Rust
1 parent 3ed435d commit 4da3da7

25 files changed

Lines changed: 3140 additions & 14 deletions

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ jobs:
2222
- name: Install dependencies
2323
run: npm ci
2424

25+
- name: Run TypeScript checks
26+
run: npm run typecheck
27+
2528
- name: Run linting
2629
run: npm run lint

.github/workflows/tests.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [main, develop]
6+
7+
jobs:
8+
rust-tests:
9+
name: Rust Tests
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup Rust
16+
uses: actions-rs/toolchain@v1
17+
with:
18+
toolchain: stable
19+
override: true
20+
21+
- name: Install system dependencies
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y libsqlite3-dev
25+
26+
- name: Run Rust tests
27+
working-directory: src-tauri
28+
run: cargo test --verbose
29+
30+
frontend-tests:
31+
name: Frontend Tests
32+
runs-on: ubuntu-latest
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Setup Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 18
41+
cache: npm
42+
43+
- name: Install dependencies
44+
run: npm ci
45+
46+
- name: Run frontend tests
47+
run: npm run test

Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Flippio Development Commands
2+
3+
.PHONY: test test-rust test-frontend test-all lint typecheck dev build
4+
5+
# Test commands
6+
test-rust:
7+
@echo "🧪 Running Rust tests..."
8+
cd src-tauri && cargo test
9+
10+
test-frontend:
11+
@echo "🧪 Running frontend tests..."
12+
npm run test
13+
14+
test-all: test-rust test-frontend
15+
@echo "✅ All tests completed!"
16+
17+
# Quality checks
18+
lint:
19+
@echo "🔍 Running linter..."
20+
npm run lint
21+
22+
typecheck:
23+
@echo "🔍 Running TypeScript checks..."
24+
npm run typecheck
25+
26+
# Combined pre-commit checks
27+
precommit: lint typecheck test-all
28+
@echo "✅ All pre-commit checks passed!"
29+
30+
# Development
31+
dev:
32+
@echo "🚀 Starting development server..."
33+
npm run tauri:dev
34+
35+
# Build
36+
build:
37+
@echo "🏗️ Building application..."
38+
npm run tauri:build
39+
40+
# Help
41+
help:
42+
@echo "Available commands:"
43+
@echo " test-rust - Run Rust backend tests"
44+
@echo " test-frontend - Run frontend tests"
45+
@echo " test-all - Run all tests"
46+
@echo " lint - Run linter"
47+
@echo " typecheck - Run TypeScript checks"
48+
@echo " precommit - Run all quality checks"
49+
@echo " dev - Start development server"
50+
@echo " build - Build application"

docs/testing-plan.md

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
# Flippio Rust Backend Testing Plan
2+
3+
## Overview
4+
This document outlines the comprehensive testing strategy for the Flippio Tauri backend to ensure device communication reliability and prevent regressions when adding new features.
5+
6+
## Test Categories
7+
8+
### 1. Unit Tests (`tests/unit/`)
9+
10+
#### Device Helpers (`device_helpers.rs`)
11+
- **Temp Directory Management**
12+
- Create temp directories for file operations
13+
- Clean up temp directories after use
14+
- Handle permission errors
15+
- Test concurrent temp directory access
16+
17+
- **ADB Path Resolution**
18+
- Resolve bundled ADB binary path
19+
- Handle missing ADB binary
20+
- Test different OS paths
21+
22+
- **Command Output Parsing**
23+
- Parse Android device lists
24+
- Parse package information
25+
- Handle malformed ADB output
26+
- Test empty command responses
27+
28+
#### Database Helpers (`database_helpers.rs`)
29+
- **Connection Pool Management**
30+
- Create and destroy SQLite pools
31+
- Handle concurrent database access
32+
- Test connection failures
33+
- Pool state synchronization
34+
35+
- **Database Operations**
36+
- Table listing and schema queries
37+
- Data retrieval and validation
38+
- Foreign key constraint handling
39+
- Error recovery scenarios
40+
41+
#### iOS Helpers (`ios_helpers.rs`)
42+
- **Device Discovery**
43+
- iOS device enumeration
44+
- Device status validation
45+
- Handle disconnected devices
46+
- Tool availability checks
47+
48+
- **App and Database Listing**
49+
- iOS app enumeration
50+
- Database file discovery
51+
- Bundle ID validation
52+
- Path resolution
53+
54+
- **Command Construction**
55+
- idevice_id command building
56+
- ideviceinstaller arguments
57+
- afcclient file transfer commands
58+
- Error handling for invalid UDIDs
59+
60+
#### File Utilities (`file_utilities.rs`)
61+
- **Temporary File Management**
62+
- Create and manage temp files
63+
- File permission handling
64+
- Binary file operations
65+
- Directory traversal
66+
67+
- **Security and Validation**
68+
- Path validation (prevent directory traversal)
69+
- File extension validation
70+
- Symlink handling
71+
- Filename sanitization
72+
73+
- **Cleanup Operations**
74+
- Automatic file cleanup
75+
- Manual cleanup procedures
76+
- Handling cleanup failures
77+
- Partial cleanup scenarios
78+
79+
### 2. Integration Tests (`tests/integration/`)
80+
81+
#### Device Database Workflow (`device_database_workflow.rs`)
82+
- **End-to-End Device Discovery**
83+
- Complete workflow from device detection to database access
84+
- iOS and Android device handling
85+
- App discovery and database enumeration
86+
- File transfer and database connection
87+
88+
- **Concurrent Device Access**
89+
- Multiple devices accessing databases simultaneously
90+
- Database switching between devices
91+
- Connection pool management across devices
92+
93+
- **Error Recovery**
94+
- Device disconnection handling
95+
- Database connection failures
96+
- Recovery from errors
97+
98+
#### File Transfer Workflow (`file_transfer_workflow.rs`)
99+
- **iOS File Transfer**
100+
- Complete afcclient transfer simulation
101+
- File integrity validation
102+
- Transfer error scenarios
103+
- Large file handling
104+
105+
- **Android File Transfer**
106+
- ADB pull command simulation
107+
- File validation after transfer
108+
- Permission and access errors
109+
110+
- **Transfer Management**
111+
- Concurrent transfers
112+
- Filename conflict resolution
113+
- Transfer cleanup procedures
114+
115+
#### Database Sync Workflow (`database_sync_workflow.rs`)
116+
- **Database Synchronization**
117+
- Device to local database sync
118+
- Multi-device database management
119+
- State consistency during operations
120+
121+
- **Connection Pool Management**
122+
- Pool creation and destruction
123+
- Concurrent pool access
124+
- Pool state transitions
125+
126+
- **Refresh Cycles**
127+
- Database refresh from device
128+
- State management during refresh
129+
- Error handling during sync
130+
131+
### 3. Test Fixtures (`tests/fixtures/`)
132+
133+
#### Mock Devices (`mock_devices.rs`)
134+
- iOS and Android device mocks
135+
- App and database mocks
136+
- Realistic test data
137+
138+
#### Test Databases (`test_databases.rs`)
139+
- SQLite database creation with sqlx
140+
- Complex schema with relationships
141+
- Corrupted and empty database scenarios
142+
143+
#### Temporary Files (`temp_files.rs`)
144+
- Thread-safe temporary file manager
145+
- Automatic cleanup capabilities
146+
- Cross-platform compatibility
147+
148+
## Running Tests
149+
150+
### All Tests
151+
```bash
152+
cargo test
153+
```
154+
155+
### Unit Tests Only
156+
```bash
157+
cargo test unit
158+
```
159+
160+
### Integration Tests Only
161+
```bash
162+
cargo test integration
163+
```
164+
165+
### Specific Test Module
166+
```bash
167+
cargo test device_helpers
168+
cargo test database_sync
169+
```
170+
171+
### Serial Tests (for resource-sensitive tests)
172+
```bash
173+
cargo test -- --test-threads=1
174+
```
175+
176+
## Test Coverage Goals
177+
178+
### Critical Paths (Must be tested)
179+
- Device discovery and connection
180+
- Database file transfer
181+
- SQLite connection and query execution
182+
- Error handling and recovery
183+
- Temporary file management
184+
185+
### Error Scenarios (Must handle gracefully)
186+
- Device disconnection during transfer
187+
- Corrupted database files
188+
- Permission denied errors
189+
- Network timeouts
190+
- Invalid command responses
191+
192+
### Performance Considerations
193+
- Concurrent device access
194+
- Large database file transfers
195+
- Memory usage during operations
196+
- Connection pool efficiency
197+
198+
## Continuous Integration
199+
200+
### Pre-commit Checks
201+
- All unit tests must pass
202+
- No compilation warnings
203+
- Code formatting with rustfmt
204+
- Clippy lints
205+
206+
### CI Pipeline
207+
- Test on multiple Rust versions
208+
- Cross-platform testing (macOS, Windows, Linux)
209+
- Memory leak detection
210+
- Performance regression tests
211+
212+
## Mock Strategy
213+
214+
### External Dependencies
215+
- **ADB Commands**: Mock output using predefined responses
216+
- **iOS Tools**: Simulate idevice command responses
217+
- **File System**: Use temporary directories for all file operations
218+
- **Network**: Mock any network-dependent operations
219+
220+
### Database Testing
221+
- Use in-memory SQLite for fast tests
222+
- Create realistic schema and data
223+
- Test both successful and error conditions
224+
225+
## Maintenance
226+
227+
### Adding New Features
228+
1. Write tests for new functionality first (TDD)
229+
2. Ensure all existing tests still pass
230+
3. Add integration tests for new workflows
231+
4. Update this testing plan document
232+
233+
### Regression Prevention
234+
- Never skip tests when adding features
235+
- Run full test suite before merging
236+
- Monitor test execution time
237+
- Keep test data realistic and comprehensive
238+
239+
## Test Environment Setup
240+
241+
### Required Tools
242+
- Rust 1.70+ (for tokio and sqlx compatibility)
243+
- SQLite 3.x
244+
- Tokio runtime for async tests
245+
246+
### Test Data
247+
- Realistic device UDIDs and names
248+
- Valid SQLite database files
249+
- Appropriate file sizes for transfer tests
250+
- Error scenarios and edge cases
251+
252+
This testing plan ensures that the Flippio backend maintains reliability while allowing for safe feature development and prevents regressions in critical device communication functionality.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"build:renderer": "cd src/renderer && vite build",
1717
"test": "vitest run --config vitest.config.ts",
1818
"test:coverage": "vitest run --coverage --config vitest.config.ts",
19+
"test:rust": "cd src-tauri && cargo test",
20+
"test:all": "npm run test && npm run test:rust",
21+
"precommit": "npm run lint && npm run typecheck && npm run test:all",
1922
"tauri": "tauri",
2023
"tauri:dev": "tauri dev",
2124
"tauri:build": "tauri build && ./scripts/post-bundle.sh",

src-tauri/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ log = "0.4"
2828
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
2929
tauri-plugin-updater = "2.0"
3030

31+
# Test dependencies
32+
[dev-dependencies]
33+
tokio-test = "0.4"
34+
tempfile = "3.10"
35+
assert_fs = "1.1"
36+
predicates = "3.1"
37+
mockall = "0.12"
38+
serial_test = "3.1"
39+
rstest = "0.19"
40+
3141
[features]
3242
default = ["custom-protocol"]
3343
custom-protocol = ["tauri/custom-protocol"]

0 commit comments

Comments
 (0)