@newpeak/barista-cli 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/arabica/auth/index.d.ts +3 -0
- package/dist/commands/arabica/auth/index.d.ts.map +1 -0
- package/dist/commands/arabica/auth/index.js +244 -0
- package/dist/commands/arabica/auth/index.js.map +1 -0
- package/dist/commands/arabica/auth/login.d.ts +3 -0
- package/dist/commands/arabica/auth/login.d.ts.map +1 -0
- package/dist/commands/arabica/auth/login.js +5 -0
- package/dist/commands/arabica/auth/login.js.map +1 -0
- package/dist/commands/arabica/auth/logout.d.ts +3 -0
- package/dist/commands/arabica/auth/logout.d.ts.map +1 -0
- package/dist/commands/arabica/auth/logout.js +5 -0
- package/dist/commands/arabica/auth/logout.js.map +1 -0
- package/dist/commands/arabica/auth/register.d.ts +3 -0
- package/dist/commands/arabica/auth/register.d.ts.map +1 -0
- package/dist/commands/arabica/auth/register.js +5 -0
- package/dist/commands/arabica/auth/register.js.map +1 -0
- package/dist/commands/arabica/auth/status.d.ts +3 -0
- package/dist/commands/arabica/auth/status.d.ts.map +1 -0
- package/dist/commands/arabica/auth/status.js +5 -0
- package/dist/commands/arabica/auth/status.js.map +1 -0
- package/dist/commands/arabica/index.d.ts +3 -0
- package/dist/commands/arabica/index.d.ts.map +1 -0
- package/dist/commands/arabica/index.js +20 -0
- package/dist/commands/arabica/index.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +92 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +50 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/liberica/auth/index.d.ts +3 -0
- package/dist/commands/liberica/auth/index.d.ts.map +1 -0
- package/dist/commands/liberica/auth/index.js +152 -0
- package/dist/commands/liberica/auth/index.js.map +1 -0
- package/dist/commands/liberica/context/index.d.ts +3 -0
- package/dist/commands/liberica/context/index.d.ts.map +1 -0
- package/dist/commands/liberica/context/index.js +36 -0
- package/dist/commands/liberica/context/index.js.map +1 -0
- package/dist/commands/liberica/employees/create.d.ts +3 -0
- package/dist/commands/liberica/employees/create.d.ts.map +1 -0
- package/dist/commands/liberica/employees/create.js +262 -0
- package/dist/commands/liberica/employees/create.js.map +1 -0
- package/dist/commands/liberica/employees/delete.d.ts +3 -0
- package/dist/commands/liberica/employees/delete.d.ts.map +1 -0
- package/dist/commands/liberica/employees/delete.js +119 -0
- package/dist/commands/liberica/employees/delete.js.map +1 -0
- package/dist/commands/liberica/employees/disable.d.ts +3 -0
- package/dist/commands/liberica/employees/disable.d.ts.map +1 -0
- package/dist/commands/liberica/employees/disable.js +88 -0
- package/dist/commands/liberica/employees/disable.js.map +1 -0
- package/dist/commands/liberica/employees/enable.d.ts +3 -0
- package/dist/commands/liberica/employees/enable.d.ts.map +1 -0
- package/dist/commands/liberica/employees/enable.js +88 -0
- package/dist/commands/liberica/employees/enable.js.map +1 -0
- package/dist/commands/liberica/employees/get.d.ts +3 -0
- package/dist/commands/liberica/employees/get.d.ts.map +1 -0
- package/dist/commands/liberica/employees/get.js +104 -0
- package/dist/commands/liberica/employees/get.js.map +1 -0
- package/dist/commands/liberica/employees/index.d.ts +3 -0
- package/dist/commands/liberica/employees/index.d.ts.map +1 -0
- package/dist/commands/liberica/employees/index.js +21 -0
- package/dist/commands/liberica/employees/index.js.map +1 -0
- package/dist/commands/liberica/employees/list.d.ts +3 -0
- package/dist/commands/liberica/employees/list.d.ts.map +1 -0
- package/dist/commands/liberica/employees/list.js +98 -0
- package/dist/commands/liberica/employees/list.js.map +1 -0
- package/dist/commands/liberica/employees/update.d.ts +3 -0
- package/dist/commands/liberica/employees/update.d.ts.map +1 -0
- package/dist/commands/liberica/employees/update.js +147 -0
- package/dist/commands/liberica/employees/update.js.map +1 -0
- package/dist/commands/liberica/index.d.ts +3 -0
- package/dist/commands/liberica/index.d.ts.map +1 -0
- package/dist/commands/liberica/index.js +33 -0
- package/dist/commands/liberica/index.js.map +1 -0
- package/dist/commands/liberica/orgs/index.d.ts +3 -0
- package/dist/commands/liberica/orgs/index.d.ts.map +1 -0
- package/dist/commands/liberica/orgs/index.js +27 -0
- package/dist/commands/liberica/orgs/index.js.map +1 -0
- package/dist/commands/liberica/positions/index.d.ts +3 -0
- package/dist/commands/liberica/positions/index.d.ts.map +1 -0
- package/dist/commands/liberica/positions/index.js +24 -0
- package/dist/commands/liberica/positions/index.js.map +1 -0
- package/dist/commands/liberica/roles/index.d.ts +3 -0
- package/dist/commands/liberica/roles/index.d.ts.map +1 -0
- package/dist/commands/liberica/roles/index.js +50 -0
- package/dist/commands/liberica/roles/index.js.map +1 -0
- package/dist/commands/liberica/users/create.d.ts +3 -0
- package/dist/commands/liberica/users/create.d.ts.map +1 -0
- package/dist/commands/liberica/users/create.js +112 -0
- package/dist/commands/liberica/users/create.js.map +1 -0
- package/dist/commands/liberica/users/delete.d.ts +3 -0
- package/dist/commands/liberica/users/delete.d.ts.map +1 -0
- package/dist/commands/liberica/users/delete.js +41 -0
- package/dist/commands/liberica/users/delete.js.map +1 -0
- package/dist/commands/liberica/users/disable.d.ts +3 -0
- package/dist/commands/liberica/users/disable.d.ts.map +1 -0
- package/dist/commands/liberica/users/disable.js +34 -0
- package/dist/commands/liberica/users/disable.js.map +1 -0
- package/dist/commands/liberica/users/enable.d.ts +3 -0
- package/dist/commands/liberica/users/enable.d.ts.map +1 -0
- package/dist/commands/liberica/users/enable.js +24 -0
- package/dist/commands/liberica/users/enable.js.map +1 -0
- package/dist/commands/liberica/users/get.d.ts +3 -0
- package/dist/commands/liberica/users/get.d.ts.map +1 -0
- package/dist/commands/liberica/users/get.js +38 -0
- package/dist/commands/liberica/users/get.js.map +1 -0
- package/dist/commands/liberica/users/index.d.ts +3 -0
- package/dist/commands/liberica/users/index.d.ts.map +1 -0
- package/dist/commands/liberica/users/index.js +25 -0
- package/dist/commands/liberica/users/index.js.map +1 -0
- package/dist/commands/liberica/users/list.d.ts +3 -0
- package/dist/commands/liberica/users/list.d.ts.map +1 -0
- package/dist/commands/liberica/users/list.js +59 -0
- package/dist/commands/liberica/users/list.js.map +1 -0
- package/dist/commands/liberica/users/me.d.ts +3 -0
- package/dist/commands/liberica/users/me.d.ts.map +1 -0
- package/dist/commands/liberica/users/me.js +34 -0
- package/dist/commands/liberica/users/me.js.map +1 -0
- package/dist/commands/liberica/users/reset-password.d.ts +3 -0
- package/dist/commands/liberica/users/reset-password.d.ts.map +1 -0
- package/dist/commands/liberica/users/reset-password.js +35 -0
- package/dist/commands/liberica/users/reset-password.js.map +1 -0
- package/dist/commands/liberica/users/update.d.ts +3 -0
- package/dist/commands/liberica/users/update.d.ts.map +1 -0
- package/dist/commands/liberica/users/update.js +42 -0
- package/dist/commands/liberica/users/update.js.map +1 -0
- package/dist/core/api/client.d.ts +114 -0
- package/dist/core/api/client.d.ts.map +1 -0
- package/dist/core/api/client.js +644 -0
- package/dist/core/api/client.js.map +1 -0
- package/dist/core/auth/token-manager.d.ts +26 -0
- package/dist/core/auth/token-manager.d.ts.map +1 -0
- package/dist/core/auth/token-manager.js +158 -0
- package/dist/core/auth/token-manager.js.map +1 -0
- package/dist/core/config/manager.d.ts +17 -0
- package/dist/core/config/manager.d.ts.map +1 -0
- package/dist/core/config/manager.js +153 -0
- package/dist/core/config/manager.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/types/employee.d.ts +87 -0
- package/dist/types/employee.d.ts.map +1 -0
- package/dist/types/employee.js +2 -0
- package/dist/types/employee.js.map +1 -0
- package/dist/types/index.d.ts +66 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/org.d.ts +22 -0
- package/dist/types/org.d.ts.map +1 -0
- package/dist/types/org.js +2 -0
- package/dist/types/org.js.map +1 -0
- package/dist/types/position.d.ts +21 -0
- package/dist/types/position.d.ts.map +1 -0
- package/dist/types/position.js +2 -0
- package/dist/types/position.js.map +1 -0
- package/dist/types/user.d.ts +59 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +2 -0
- package/dist/types/user.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/.eslintrc.json +0 -23
- package/.prettierrc +0 -9
- package/.sisyphus/notepads/liberica-employees/learnings.md +0 -73
- package/AGENTS.md +0 -270
- package/CONTRIBUTING.md +0 -291
- package/tests/unit/commands/arabica/auth.test.ts +0 -230
- package/tests/unit/commands/liberica/auth.test.ts +0 -175
- package/tests/unit/commands/liberica/context.test.ts +0 -98
- package/tests/unit/commands/liberica/employees/create.test.ts +0 -463
- package/tests/unit/commands/liberica/employees/disable.test.ts +0 -82
- package/tests/unit/commands/liberica/employees/enable.test.ts +0 -82
- package/tests/unit/commands/liberica/employees/get.test.ts +0 -111
- package/tests/unit/commands/liberica/employees/list.test.ts +0 -294
- package/tests/unit/commands/liberica/employees/update.test.ts +0 -210
- package/tests/unit/config.test.ts +0 -141
- package/tests/unit/types.test.ts +0 -195
- package/tsconfig.json +0 -20
package/CONTRIBUTING.md
DELETED
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
# Contributing to Barista CLI
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing to Barista CLI! This document provides guidelines and instructions for contributing.
|
|
4
|
-
|
|
5
|
-
## Development Setup
|
|
6
|
-
|
|
7
|
-
### Prerequisites
|
|
8
|
-
|
|
9
|
-
- Node.js 18+
|
|
10
|
-
- npm 9+
|
|
11
|
-
|
|
12
|
-
### Initial Setup
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
# Clone the repository
|
|
16
|
-
git clone https://gitlab.newpeaksh.com/coffee/coffee-barista-cli.git
|
|
17
|
-
cd coffee-barista-cli
|
|
18
|
-
|
|
19
|
-
# Install dependencies
|
|
20
|
-
npm install
|
|
21
|
-
|
|
22
|
-
# Link CLI for local development
|
|
23
|
-
npm link
|
|
24
|
-
|
|
25
|
-
# Verify installation
|
|
26
|
-
barista --version
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### VS Code Setup
|
|
30
|
-
|
|
31
|
-
Recommended extensions:
|
|
32
|
-
- ESLint
|
|
33
|
-
- Prettier
|
|
34
|
-
- TypeScript Vue Plugin (Volar)
|
|
35
|
-
|
|
36
|
-
## Development Workflow
|
|
37
|
-
|
|
38
|
-
### ⚠️ IMPORTANT: Design First, Code Later
|
|
39
|
-
|
|
40
|
-
**Before writing ANY code, you MUST complete the design phase.**
|
|
41
|
-
|
|
42
|
-
Skipping design leads to:
|
|
43
|
-
- Wrong API endpoints (like Arabica register using `/api/member/user/register` instead of `/member/user/register`)
|
|
44
|
-
- Missing required parameters
|
|
45
|
-
- Inconsistent command structures
|
|
46
|
-
- Rework and wasted time
|
|
47
|
-
|
|
48
|
-
### 1. Design Phase (MANDATORY)
|
|
49
|
-
|
|
50
|
-
1. Read `docs/COMMAND_DESIGN_SPEC.md`
|
|
51
|
-
2. Find backend Controller:
|
|
52
|
-
```bash
|
|
53
|
-
# Example: Find the register endpoint
|
|
54
|
-
grep -r "register" --include="*.java" ../coffee-arabica-end/facade/
|
|
55
|
-
```
|
|
56
|
-
3. Document the command design:
|
|
57
|
-
- API endpoint and HTTP method
|
|
58
|
-
- All parameters (required vs optional)
|
|
59
|
-
- Request/Response DTOs
|
|
60
|
-
- Error codes and handling
|
|
61
|
-
4. Create design document: `docs/commands/{service}/{resource}/{action}/index.md`
|
|
62
|
-
5. **Get design reviewed** before coding
|
|
63
|
-
|
|
64
|
-
### 2. Create a Branch
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
git checkout -b feature/my-feature
|
|
68
|
-
# or
|
|
69
|
-
git checkout -b fix/bug-description
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### 3. Implement Changes (After Design Approved)
|
|
73
|
-
|
|
74
|
-
- Write TypeScript code following the approved design
|
|
75
|
-
- Follow existing command patterns
|
|
76
|
-
- Add or update tests
|
|
77
|
-
- Update documentation if needed
|
|
78
|
-
|
|
79
|
-
### 4. Run Tests
|
|
80
|
-
|
|
81
|
-
```bash
|
|
82
|
-
# Run all tests
|
|
83
|
-
npm test
|
|
84
|
-
|
|
85
|
-
# Run unit tests only
|
|
86
|
-
npm run test:unit
|
|
87
|
-
|
|
88
|
-
# Run tests in watch mode
|
|
89
|
-
npm test -- --watch
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### 5. Lint and Format
|
|
93
|
-
|
|
94
|
-
```bash
|
|
95
|
-
# Check code style
|
|
96
|
-
npm run lint
|
|
97
|
-
|
|
98
|
-
# Auto-fix linting issues
|
|
99
|
-
npm run lint -- --fix
|
|
100
|
-
|
|
101
|
-
# Format code with Prettier
|
|
102
|
-
npm run format
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### 6. Build
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
# Build TypeScript
|
|
109
|
-
npm run build
|
|
110
|
-
|
|
111
|
-
# Watch mode for development
|
|
112
|
-
npm run dev
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### 7. Commit Changes
|
|
116
|
-
|
|
117
|
-
Follow commit message conventions (see below).
|
|
118
|
-
|
|
119
|
-
### 8. Push and Create PR
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
git push origin feature/my-feature
|
|
123
|
-
# Then create PR via GitLab UI
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## Code Style
|
|
127
|
-
|
|
128
|
-
We use ESLint and Prettier for code formatting:
|
|
129
|
-
|
|
130
|
-
- **TypeScript**: Strict mode enabled
|
|
131
|
-
- **ESM**: All code uses ES modules with `.js` extensions in imports
|
|
132
|
-
- **Semicolons**: Required
|
|
133
|
-
- **Quotes**: Single quotes for strings
|
|
134
|
-
- **Indentation**: 2 spaces
|
|
135
|
-
|
|
136
|
-
### Import Order
|
|
137
|
-
|
|
138
|
-
```typescript
|
|
139
|
-
// 1. Node.js built-ins
|
|
140
|
-
import fs from 'fs';
|
|
141
|
-
import path from 'path';
|
|
142
|
-
|
|
143
|
-
// 2. External packages
|
|
144
|
-
import chalk from 'chalk';
|
|
145
|
-
import { Command } from 'commander';
|
|
146
|
-
|
|
147
|
-
// 3. Internal packages (relative)
|
|
148
|
-
import { configManager } from '../core/config/manager.js';
|
|
149
|
-
import { tokenManager } from '../core/auth/token-manager.js';
|
|
150
|
-
import type { Context, Config } from '../types/index.js';
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
## Commit Message Conventions
|
|
154
|
-
|
|
155
|
-
We follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
156
|
-
|
|
157
|
-
```
|
|
158
|
-
<type>(<scope>): <subject>
|
|
159
|
-
|
|
160
|
-
[optional body]
|
|
161
|
-
|
|
162
|
-
[optional footer]
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### Types
|
|
166
|
-
|
|
167
|
-
| Type | Description |
|
|
168
|
-
|------|-------------|
|
|
169
|
-
| feat | New feature |
|
|
170
|
-
| fix | Bug fix |
|
|
171
|
-
| docs | Documentation changes |
|
|
172
|
-
| style | Formatting, missing semicolons, etc. |
|
|
173
|
-
| refactor | Code refactoring |
|
|
174
|
-
| test | Adding tests |
|
|
175
|
-
| chore | Maintenance tasks |
|
|
176
|
-
|
|
177
|
-
### Examples
|
|
178
|
-
|
|
179
|
-
```bash
|
|
180
|
-
# Feature
|
|
181
|
-
git commit -m "feat(liberica): add orders cancel command"
|
|
182
|
-
|
|
183
|
-
# Bug fix
|
|
184
|
-
git commit -m "fix(auth): handle token expiration gracefully"
|
|
185
|
-
|
|
186
|
-
# Documentation
|
|
187
|
-
git commit -m "docs: update README with new command examples"
|
|
188
|
-
|
|
189
|
-
# Refactoring
|
|
190
|
-
git commit -m "refactor(config): extract environment validation"
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## Testing
|
|
194
|
-
|
|
195
|
-
### Test Structure
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
199
|
-
|
|
200
|
-
describe('module name', () => {
|
|
201
|
-
beforeEach(() => {
|
|
202
|
-
vi.clearAllMocks();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('should do something specific', () => {
|
|
206
|
-
// Arrange
|
|
207
|
-
const input = 'test';
|
|
208
|
-
|
|
209
|
-
// Act
|
|
210
|
-
const result = functionUnderTest(input);
|
|
211
|
-
|
|
212
|
-
// Assert
|
|
213
|
-
expect(result).toBe('expected');
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
### Running Specific Tests
|
|
219
|
-
|
|
220
|
-
```bash
|
|
221
|
-
# Run tests matching a pattern
|
|
222
|
-
npm test -- orders
|
|
223
|
-
|
|
224
|
-
# Run with coverage
|
|
225
|
-
npm test -- --coverage
|
|
226
|
-
|
|
227
|
-
# Run in watch mode for specific file
|
|
228
|
-
npm test -- src/commands/context.test.ts --watch
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
## Project Structure
|
|
232
|
-
|
|
233
|
-
```
|
|
234
|
-
coffee-barista-cli/
|
|
235
|
-
├── bin/
|
|
236
|
-
│ └── barista # CLI entry point
|
|
237
|
-
├── src/
|
|
238
|
-
│ ├── index.ts # Main entry
|
|
239
|
-
│ ├── commands/ # Command implementations
|
|
240
|
-
│ │ ├── context.ts
|
|
241
|
-
│ │ ├── auth.ts
|
|
242
|
-
│ │ ├── liberica/
|
|
243
|
-
│ │ │ ├── orders.ts
|
|
244
|
-
│ │ │ ├── products.ts
|
|
245
|
-
│ │ │ └── index.ts
|
|
246
|
-
│ │ └── arabica/
|
|
247
|
-
│ │ └── index.ts
|
|
248
|
-
│ ├── core/ # Core functionality
|
|
249
|
-
│ │ ├── config/
|
|
250
|
-
│ │ │ └── manager.ts
|
|
251
|
-
│ │ └── auth/
|
|
252
|
-
│ │ └── token-manager.ts
|
|
253
|
-
│ ├── types/
|
|
254
|
-
│ │ └── index.ts
|
|
255
|
-
│ └── utils/
|
|
256
|
-
├── tests/
|
|
257
|
-
│ ├── unit/ # Unit tests
|
|
258
|
-
│ ├── integration/ # Integration tests
|
|
259
|
-
│ └── fixtures/ # Test fixtures
|
|
260
|
-
├── docs/ # Documentation
|
|
261
|
-
└── package.json
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
## Documentation
|
|
265
|
-
|
|
266
|
-
When adding new features, update relevant docs:
|
|
267
|
-
|
|
268
|
-
- **New command**:
|
|
269
|
-
1. **必须先**阅读 [命令设计规范](./docs/COMMAND_DESIGN_SPEC.md)
|
|
270
|
-
2. 编写设计文档(按规范模板)
|
|
271
|
-
3. 更新 `docs/COMMANDS.md`
|
|
272
|
-
- **Architecture changes**: Update `docs/ARCHITECTURE.md`
|
|
273
|
-
- **README.md**: Update if CLI interface changes
|
|
274
|
-
|
|
275
|
-
## Pull Request Checklist
|
|
276
|
-
|
|
277
|
-
- [ ] Code follows style guidelines (lint passes)
|
|
278
|
-
- [ ] Tests added/updated and passing
|
|
279
|
-
- [ ] Documentation updated
|
|
280
|
-
- [ ] Commit messages follow conventions
|
|
281
|
-
- [ ] Build succeeds (`npm run build`)
|
|
282
|
-
|
|
283
|
-
## Questions?
|
|
284
|
-
|
|
285
|
-
For questions or discussions:
|
|
286
|
-
- Open an issue in the repository
|
|
287
|
-
- Contact the development team
|
|
288
|
-
|
|
289
|
-
## License
|
|
290
|
-
|
|
291
|
-
By contributing, you agree that your contributions will be licensed under the MIT License.
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
vi.mock('chalk', () => ({
|
|
4
|
-
default: {
|
|
5
|
-
bold: vi.fn((text) => text),
|
|
6
|
-
green: vi.fn((text) => text),
|
|
7
|
-
red: vi.fn((text) => text),
|
|
8
|
-
gray: vi.fn((text) => text),
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock('inquirer', () => ({
|
|
13
|
-
default: {
|
|
14
|
-
prompt: vi.fn(),
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
vi.mock('../../../../src/core/config/manager.js', () => ({
|
|
19
|
-
configManager: {
|
|
20
|
-
getCurrentContext: vi.fn(() => ({
|
|
21
|
-
environment: 'dev' as const,
|
|
22
|
-
service: 'arabica' as const,
|
|
23
|
-
})),
|
|
24
|
-
},
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
vi.mock('../../../../src/core/auth/token-manager.js', () => ({
|
|
28
|
-
tokenManager: {
|
|
29
|
-
getToken: vi.fn(),
|
|
30
|
-
setToken: vi.fn(),
|
|
31
|
-
deleteToken: vi.fn(),
|
|
32
|
-
findAllTokens: vi.fn(() => []),
|
|
33
|
-
},
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
vi.mock('../../../../src/core/api/client.js', () => ({
|
|
37
|
-
apiClient: {
|
|
38
|
-
loginArabica: vi.fn(),
|
|
39
|
-
registerArabica: vi.fn(),
|
|
40
|
-
},
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
import { createArabicaAuthCommand } from '../../../../src/commands/arabica/auth/index.js';
|
|
44
|
-
|
|
45
|
-
describe('createArabicaAuthCommand', () => {
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
vi.clearAllMocks();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should create command with name "auth"', () => {
|
|
51
|
-
const command = createArabicaAuthCommand();
|
|
52
|
-
expect(command.name()).toBe('auth');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should have description "Manage Arabica authentication"', () => {
|
|
56
|
-
const command = createArabicaAuthCommand();
|
|
57
|
-
expect(command.description()).toBe('Manage Arabica authentication');
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('login subcommand', () => {
|
|
61
|
-
it('should exist', () => {
|
|
62
|
-
const command = createArabicaAuthCommand();
|
|
63
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
64
|
-
expect(loginCmd).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should have correct description', () => {
|
|
68
|
-
const command = createArabicaAuthCommand();
|
|
69
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
70
|
-
expect(loginCmd?.description()).toBe('Login to Arabica');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should have --env option', () => {
|
|
74
|
-
const command = createArabicaAuthCommand();
|
|
75
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
76
|
-
const envOption = loginCmd?.options.find((opt) => opt.short === '-e' || opt.long === '--env');
|
|
77
|
-
expect(envOption).toBeDefined();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should have --account option', () => {
|
|
81
|
-
const command = createArabicaAuthCommand();
|
|
82
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
83
|
-
const accountOption = loginCmd?.options.find((opt) => opt.long === '--account');
|
|
84
|
-
expect(accountOption).toBeDefined();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should have --password option', () => {
|
|
88
|
-
const command = createArabicaAuthCommand();
|
|
89
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
90
|
-
const passwordOption = loginCmd?.options.find((opt) => opt.long === '--password');
|
|
91
|
-
expect(passwordOption).toBeDefined();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should have --remember option', () => {
|
|
95
|
-
const command = createArabicaAuthCommand();
|
|
96
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
97
|
-
const rememberOption = loginCmd?.options.find((opt) => opt.long === '--remember');
|
|
98
|
-
expect(rememberOption).toBeDefined();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should NOT have --tenant option', () => {
|
|
102
|
-
const command = createArabicaAuthCommand();
|
|
103
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
104
|
-
const tenantOption = loginCmd?.options.find((opt) => opt.long === '--tenant');
|
|
105
|
-
expect(tenantOption).toBeUndefined();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('register subcommand', () => {
|
|
110
|
-
it('should exist', () => {
|
|
111
|
-
const command = createArabicaAuthCommand();
|
|
112
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
113
|
-
expect(registerCmd).toBeDefined();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should have correct description', () => {
|
|
117
|
-
const command = createArabicaAuthCommand();
|
|
118
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
119
|
-
expect(registerCmd?.description()).toBe('Register new Arabica account');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should have --env option', () => {
|
|
123
|
-
const command = createArabicaAuthCommand();
|
|
124
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
125
|
-
const envOption = registerCmd?.options.find((opt) => opt.long === '--env');
|
|
126
|
-
expect(envOption).toBeDefined();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('should have --email option', () => {
|
|
130
|
-
const command = createArabicaAuthCommand();
|
|
131
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
132
|
-
const emailOption = registerCmd?.options.find((opt) => opt.long === '--email');
|
|
133
|
-
expect(emailOption).toBeDefined();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should have --password option', () => {
|
|
137
|
-
const command = createArabicaAuthCommand();
|
|
138
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
139
|
-
const passwordOption = registerCmd?.options.find((opt) => opt.long === '--password');
|
|
140
|
-
expect(passwordOption).toBeDefined();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('should have --phone option', () => {
|
|
144
|
-
const command = createArabicaAuthCommand();
|
|
145
|
-
const registerCmd = command.commands.find((cmd) => cmd.name() === 'register');
|
|
146
|
-
const phoneOption = registerCmd?.options.find((opt) => opt.long === '--phone');
|
|
147
|
-
expect(phoneOption).toBeDefined();
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('status subcommand', () => {
|
|
152
|
-
it('should exist', () => {
|
|
153
|
-
const command = createArabicaAuthCommand();
|
|
154
|
-
const statusCmd = command.commands.find((cmd) => cmd.name() === 'status');
|
|
155
|
-
expect(statusCmd).toBeDefined();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should have correct description', () => {
|
|
159
|
-
const command = createArabicaAuthCommand();
|
|
160
|
-
const statusCmd = command.commands.find((cmd) => cmd.name() === 'status');
|
|
161
|
-
expect(statusCmd?.description()).toBe('Check Arabica authentication status');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should have no options', () => {
|
|
165
|
-
const command = createArabicaAuthCommand();
|
|
166
|
-
const statusCmd = command.commands.find((cmd) => cmd.name() === 'status');
|
|
167
|
-
expect(statusCmd?.options).toHaveLength(0);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
describe('logout subcommand', () => {
|
|
172
|
-
it('should exist', () => {
|
|
173
|
-
const command = createArabicaAuthCommand();
|
|
174
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
175
|
-
expect(logoutCmd).toBeDefined();
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should have correct description', () => {
|
|
179
|
-
const command = createArabicaAuthCommand();
|
|
180
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
181
|
-
expect(logoutCmd?.description()).toBe('Logout from Arabica and clear token');
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should have --env option', () => {
|
|
185
|
-
const command = createArabicaAuthCommand();
|
|
186
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
187
|
-
const envOption = logoutCmd?.options.find((opt) => opt.long === '--env');
|
|
188
|
-
expect(envOption).toBeDefined();
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should have --all option', () => {
|
|
192
|
-
const command = createArabicaAuthCommand();
|
|
193
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
194
|
-
const allOption = logoutCmd?.options.find((opt) => opt.long === '--all');
|
|
195
|
-
expect(allOption).toBeDefined();
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('auth command integration', () => {
|
|
201
|
-
it('should call apiClient.loginArabica with correct parameters on login', async () => {
|
|
202
|
-
const { apiClient } = await import('../../../../src/core/api/client.js');
|
|
203
|
-
expect(apiClient.loginArabica).toBeDefined();
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should call apiClient.registerArabica with correct parameters on register', async () => {
|
|
207
|
-
const { apiClient } = await import('../../../../src/core/api/client.js');
|
|
208
|
-
expect(apiClient.registerArabica).toBeDefined();
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('should call tokenManager.setToken after successful login', async () => {
|
|
212
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
213
|
-
expect(tokenManager.setToken).toBeDefined();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should call tokenManager.getToken for status check', async () => {
|
|
217
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
218
|
-
expect(tokenManager.getToken).toBeDefined();
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should call tokenManager.deleteToken on logout', async () => {
|
|
222
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
223
|
-
expect(tokenManager.deleteToken).toBeDefined();
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('should call tokenManager.findAllTokens on logout --all', async () => {
|
|
227
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
228
|
-
expect(tokenManager.findAllTokens).toBeDefined();
|
|
229
|
-
});
|
|
230
|
-
});
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
|
|
3
|
-
vi.mock('chalk', () => ({
|
|
4
|
-
default: {
|
|
5
|
-
bold: vi.fn((text) => text),
|
|
6
|
-
green: vi.fn((text) => text),
|
|
7
|
-
red: vi.fn((text) => text),
|
|
8
|
-
gray: vi.fn((text) => text),
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock('inquirer', () => ({
|
|
13
|
-
default: {
|
|
14
|
-
prompt: vi.fn(),
|
|
15
|
-
},
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
vi.mock('../../../../src/core/config/manager.js', () => ({
|
|
19
|
-
configManager: {
|
|
20
|
-
getCurrentContext: vi.fn(() => ({
|
|
21
|
-
environment: 'dev' as const,
|
|
22
|
-
service: 'liberica' as const,
|
|
23
|
-
tenant: 'test-tenant',
|
|
24
|
-
})),
|
|
25
|
-
setTenant: vi.fn(),
|
|
26
|
-
},
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
vi.mock('../../../../src/core/auth/token-manager.js', () => ({
|
|
30
|
-
tokenManager: {
|
|
31
|
-
getToken: vi.fn(),
|
|
32
|
-
setToken: vi.fn(),
|
|
33
|
-
deleteToken: vi.fn(),
|
|
34
|
-
findAllTokens: vi.fn(() => []),
|
|
35
|
-
},
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
vi.mock('../../../../src/core/api/client.js', () => ({
|
|
39
|
-
apiClient: {
|
|
40
|
-
login: vi.fn(),
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
|
|
44
|
-
import { createLibericaAuthCommand } from '../../../../src/commands/liberica/auth/index.js';
|
|
45
|
-
|
|
46
|
-
describe('createLibericaAuthCommand', () => {
|
|
47
|
-
beforeEach(() => {
|
|
48
|
-
vi.clearAllMocks();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should create command with name "auth"', () => {
|
|
52
|
-
const command = createLibericaAuthCommand();
|
|
53
|
-
expect(command.name()).toBe('auth');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should have description "Manage Liberica authentication"', () => {
|
|
57
|
-
const command = createLibericaAuthCommand();
|
|
58
|
-
expect(command.description()).toBe('Manage Liberica authentication');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
describe('login subcommand', () => {
|
|
62
|
-
it('should exist', () => {
|
|
63
|
-
const command = createLibericaAuthCommand();
|
|
64
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
65
|
-
expect(loginCmd).toBeDefined();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should have correct description', () => {
|
|
69
|
-
const command = createLibericaAuthCommand();
|
|
70
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
71
|
-
expect(loginCmd?.description()).toBe('Login to Liberica');
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should have --env option', () => {
|
|
75
|
-
const command = createLibericaAuthCommand();
|
|
76
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
77
|
-
const envOption = loginCmd?.options.find((opt) => opt.short === '-e' || opt.long === '--env');
|
|
78
|
-
expect(envOption).toBeDefined();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should have --tenant option', () => {
|
|
82
|
-
const command = createLibericaAuthCommand();
|
|
83
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
84
|
-
const tenantOption = loginCmd?.options.find((opt) => opt.long === '--tenant');
|
|
85
|
-
expect(tenantOption).toBeDefined();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should have --username option', () => {
|
|
89
|
-
const command = createLibericaAuthCommand();
|
|
90
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
91
|
-
const usernameOption = loginCmd?.options.find((opt) => opt.long === '--username');
|
|
92
|
-
expect(usernameOption).toBeDefined();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should have --password option', () => {
|
|
96
|
-
const command = createLibericaAuthCommand();
|
|
97
|
-
const loginCmd = command.commands.find((cmd) => cmd.name() === 'login');
|
|
98
|
-
const passwordOption = loginCmd?.options.find((opt) => opt.long === '--password');
|
|
99
|
-
expect(passwordOption).toBeDefined();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('status subcommand', () => {
|
|
104
|
-
it('should exist', () => {
|
|
105
|
-
const command = createLibericaAuthCommand();
|
|
106
|
-
const statusCmd = command.commands.find((cmd) => cmd.name() === 'status');
|
|
107
|
-
expect(statusCmd).toBeDefined();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('should have correct description', () => {
|
|
111
|
-
const command = createLibericaAuthCommand();
|
|
112
|
-
const statusCmd = command.commands.find((cmd) => cmd.name() === 'status');
|
|
113
|
-
expect(statusCmd?.description()).toBe('Check Liberica authentication status');
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('logout subcommand', () => {
|
|
118
|
-
it('should exist', () => {
|
|
119
|
-
const command = createLibericaAuthCommand();
|
|
120
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
121
|
-
expect(logoutCmd).toBeDefined();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should have correct description', () => {
|
|
125
|
-
const command = createLibericaAuthCommand();
|
|
126
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
127
|
-
expect(logoutCmd?.description()).toBe('Logout from Liberica and clear token');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should have --env option', () => {
|
|
131
|
-
const command = createLibericaAuthCommand();
|
|
132
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
133
|
-
const envOption = logoutCmd?.options.find((opt) => opt.long === '--env');
|
|
134
|
-
expect(envOption).toBeDefined();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should have --all option', () => {
|
|
138
|
-
const command = createLibericaAuthCommand();
|
|
139
|
-
const logoutCmd = command.commands.find((cmd) => cmd.name() === 'logout');
|
|
140
|
-
const allOption = logoutCmd?.options.find((opt) => opt.long === '--all');
|
|
141
|
-
expect(allOption).toBeDefined();
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('auth command integration', () => {
|
|
147
|
-
it('should call apiClient.login with correct parameters on login', async () => {
|
|
148
|
-
const { apiClient } = await import('../../../../src/core/api/client.js');
|
|
149
|
-
const { configManager } = await import('../../../../src/core/config/manager.js');
|
|
150
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
151
|
-
|
|
152
|
-
(apiClient.login as ReturnType<typeof vi.fn>).mockResolvedValue({
|
|
153
|
-
success: true,
|
|
154
|
-
data: { token: 'test-token', expiresAt: '2024-12-31' },
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
(configManager.getCurrentContext as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
158
|
-
environment: 'dev',
|
|
159
|
-
service: 'liberica',
|
|
160
|
-
tenant: 'test-tenant',
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
expect(apiClient.login).toBeDefined();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should call tokenManager.setToken after successful login', async () => {
|
|
167
|
-
const { tokenManager } = await import('../../../../src/core/auth/token-manager.js');
|
|
168
|
-
expect(tokenManager.setToken).toBeDefined();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should call configManager.setTenant after successful login', async () => {
|
|
172
|
-
const { configManager } = await import('../../../../src/core/config/manager.js');
|
|
173
|
-
expect(configManager.setTenant).toBeDefined();
|
|
174
|
-
});
|
|
175
|
-
});
|