# SIM API Test Tracking

## Overview

The test tracking system automatically logs all Freebit API calls made during physical SIM testing to a CSV file. This allows you to track which APIs were tested on which phones and at what time.

## Log File Location

The test tracking log file is created at the project root:

- **File**: `sim-api-test-log.csv`
- **Location**: Project root directory

## Log Format

The CSV file contains the following columns:

1. **Timestamp** - ISO 8601 timestamp of when the API was called
2. **API Endpoint** - The Freebit API endpoint (e.g., `/mvno/getDetail/`, `/master/addSpec/`)
3. **API Method** - HTTP method (typically "POST")
4. **Phone Number** - The phone number/SIM account identifier
5. **SIM Identifier** - Additional SIM identifier if available
6. **Request Payload** - JSON string of the request (sensitive data redacted)
7. **Response Status** - Success or error status code
8. **Error** - Error message if the call failed
9. **Additional Info** - Additional status information

## What Gets Tracked

The system automatically tracks all Freebit API calls that include a phone number/account identifier, including:

- **Physical SIM Activation** (`/master/addSpec/` or `/mvno/eachQuota/`)
- **SIM Top-up** (`/master/addSpec/` or `/mvno/eachQuota/`)
- **SIM Details** (`/mvno/getDetail/`)
- **SIM Usage** (`/mvno/getTrafficInfo/`)
- **Plan Changes** (`/mvno/changePlan/`)
- **SIM Cancellation** (`/mvno/releasePlan/`)
- **eSIM Operations** (`/esim/reissueProfile/`, `/mvno/esim/addAcnt/`)
- **Quota History** (`/mvno/getQuotaHistory/`)

## Usage

The tracking is **automatic** - no code changes needed. Every time a Freebit API is called with a phone number, it will be logged to the CSV file.

### Example Log Entry

```csv
Timestamp,API Endpoint,API Method,Phone Number,SIM Identifier,Request Payload,Response Status,Error,Additional Info
2025-01-15T10:30:45.123Z,/master/addSpec/,POST,02000002470001,02000002470001,"{""account"":""02000002470001"",""quota"":0}",Success,,"OK"
```

## Test Data Files

The following CSV files contain test SIM data:

- `ASI_N6_PASI_20251229.csv` - 半黒データ (Half-black data) - 50 SIMs (rows 1-50)
- `ASI_N7_PASI_20251229.csv` - 半黒音声 (Half-black voice) - 50 SIMs (rows 51-100)

Each row contains:

- Row number
- SIM number (phone number)
- PT number
- PASI identifier
- Date (20251229)

## Notes

- The tracking system only logs API calls that include a phone number/account identifier
- Tracking failures do not affect API functionality - if logging fails, the API call still proceeds
- The log file is append-only - new entries are added to the end of the file
- Request payloads are redacted for security (sensitive data like auth keys are removed)

## Viewing the Log

You can view the log file using any CSV viewer or text editor:

```bash
# View the log file
cat sim-api-test-log.csv

# View last 20 entries
tail -20 sim-api-test-log.csv

# Filter by phone number
grep "02000002470001" sim-api-test-log.csv
```
