feat: introduce Jest testing framework and decouple Product logic
- Added Jest infrastructure (deps, config, global mocks) - Introduced ISpreadsheetService with GAS and Mock implementations - Refactored Product.ts to use dependency injection - Added unit tests for Product class - Updated documentation (README, SETUP, ARCHITECTURE) to reflect testing and init scripts
This commit is contained in:
@ -38,6 +38,13 @@ The system allows you to:
|
|||||||
npm run deploy
|
npm run deploy
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Run unit tests using Jest:
|
||||||
|
```bash
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
- `src/`: Source code (TypeScript)
|
- `src/`: Source code (TypeScript)
|
||||||
|
|||||||
@ -86,3 +86,14 @@ A dedicated side panel provides visibility into the background queue system.
|
|||||||
- Displays pending edits with timestamps.
|
- Displays pending edits with timestamps.
|
||||||
- Provides controls to globally enable/disable processing.
|
- Provides controls to globally enable/disable processing.
|
||||||
- Allows manual intervention (delete/push) for individual items.
|
- Allows manual intervention (delete/push) for individual items.
|
||||||
|
|
||||||
|
### 6. Service Layer & Testing
|
||||||
|
|
||||||
|
To enable unit testing without Google Apps Script dependencies, the project uses a Service pattern with Dependency Injection.
|
||||||
|
|
||||||
|
- **`ISpreadsheetService`**: Interface for all sheet interactions.
|
||||||
|
- **`GASSpreadsheetService`**: Production implementation wrapping `SpreadsheetApp`.
|
||||||
|
- **`MockSpreadsheetService`**: In-memory implementation for tests.
|
||||||
|
|
||||||
|
Classes (like `Product`) should accept an `ISpreadsheetService` in their constructor. This allows providing the Mock service during tests to verify logic without touching real Google Sheets.
|
||||||
|
|
||||||
|
|||||||
@ -2,23 +2,24 @@
|
|||||||
|
|
||||||
## Local Development Environment
|
## Local Development Environment
|
||||||
|
|
||||||
1. **Install Node.js**
|
1. **Environment Initialization**
|
||||||
This project uses `fnm` to manage Node versions.
|
Run the provided PowerShell script to automatically install:
|
||||||
|
- `fnm` (Fast Node Manager) via Winget
|
||||||
|
- Node.js (v22)
|
||||||
|
- Global dependencies (`@google/clasp`)
|
||||||
|
- Project dependencies (`npm install`)
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
# Install fnm (if not installed)
|
.\init.ps1
|
||||||
winget install Schniz.fnm
|
|
||||||
# Configure environment
|
|
||||||
fnm env --use-on-cd | Out-String | Invoke-Expression
|
|
||||||
# Install Node version
|
|
||||||
fnm use --install-if-missing 22
|
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **Install Dependencies**
|
2. **Verify Installation**
|
||||||
|
Run tests to confirm the environment is correctly configured.
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm test
|
||||||
npm install -g @google/clasp
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
3. **Clasp Login**
|
3. **Clasp Login**
|
||||||
Authenticate with Google to allow pushing code.
|
Authenticate with Google to allow pushing code.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user