From 9bc55f3a065ddf5e7212f33ae872799318760a96 Mon Sep 17 00:00:00 2001 From: Ben Miller Date: Thu, 25 Dec 2025 03:59:23 -0700 Subject: [PATCH] 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 --- README.md | 7 +++++++ docs/ARCHITECTURE.md | 11 +++++++++++ docs/SETUP.md | 23 ++++++++++++----------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ff8d06c..f3b6e04 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,13 @@ The system allows you to: npm run deploy ``` +## Testing + +Run unit tests using Jest: +```bash +npm test +``` + ## Project Structure - `src/`: Source code (TypeScript) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 0d4cbfa..1e8d82e 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -86,3 +86,14 @@ A dedicated side panel provides visibility into the background queue system. - Displays pending edits with timestamps. - Provides controls to globally enable/disable processing. - 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. + diff --git a/docs/SETUP.md b/docs/SETUP.md index 811f103..4b12199 100644 --- a/docs/SETUP.md +++ b/docs/SETUP.md @@ -2,23 +2,24 @@ ## Local Development Environment -1. **Install Node.js** - This project uses `fnm` to manage Node versions. +1. **Environment Initialization** + 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 - # Install fnm (if not installed) - winget install Schniz.fnm - # Configure environment - fnm env --use-on-cd | Out-String | Invoke-Expression - # Install Node version - fnm use --install-if-missing 22 + .\init.ps1 ``` -2. **Install Dependencies** +2. **Verify Installation** + Run tests to confirm the environment is correctly configured. ```bash - npm install - npm install -g @google/clasp + npm test ``` + 3. **Clasp Login** Authenticate with Google to allow pushing code.