|
| 1 | +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ |
| 2 | +import { describe, it, expect } from 'vitest'; |
| 3 | +import { executeCLI } from '../utils/command.js'; |
| 4 | + |
| 5 | +type Application = { |
| 6 | + application_id: string; |
| 7 | + name: string; |
| 8 | + regulatory_classes: string[]; |
| 9 | + description: string; |
| 10 | + latest_version: { |
| 11 | + number: string; |
| 12 | + released_at: string; |
| 13 | + }; |
| 14 | +}; |
| 15 | + |
| 16 | +type ApplicationVersion = { |
| 17 | + number: string; |
| 18 | + released_at: string; |
| 19 | +}; |
| 20 | + |
| 21 | +describe('SWR-TSSDK-2.1: Application List Retrieval', () => { |
| 22 | + it('should retrieve all available applications for authenticated user', async () => { |
| 23 | + const { stdout, exitCode } = await executeCLI(['list-applications']); |
| 24 | + |
| 25 | + expect(exitCode).toBe(0); |
| 26 | + |
| 27 | + // Parse the applications from the output |
| 28 | + const output = String(stdout); |
| 29 | + const applicationsMatch = output.match(/Applications: (\[.*\])/s); |
| 30 | + expect(applicationsMatch).toBeTruthy(); |
| 31 | + |
| 32 | + const applications = JSON.parse(applicationsMatch![1]) as Array<Application>; |
| 33 | + expect(Array.isArray(applications)).toBe(true); |
| 34 | + }); |
| 35 | +}); |
| 36 | + |
| 37 | +describe('SWR-TSSDK-2.2: Application Details', () => { |
| 38 | + it('should provide application identification, description, and regulatory compliance information', async () => { |
| 39 | + const { stdout, exitCode } = await executeCLI(['list-applications']); |
| 40 | + |
| 41 | + expect(exitCode).toBe(0); |
| 42 | + |
| 43 | + // Parse the applications from the output |
| 44 | + const output = String(stdout); |
| 45 | + const applicationsMatch = output.match(/Applications: (\[.*\])/s); |
| 46 | + expect(applicationsMatch).toBeTruthy(); |
| 47 | + |
| 48 | + const applications = JSON.parse(applicationsMatch![1]) as Array<Application>; |
| 49 | + expect(Array.isArray(applications)).toBe(true); |
| 50 | + |
| 51 | + // Find test-app in the list |
| 52 | + const testApp = applications.find(app => app.application_id === 'test-app'); |
| 53 | + expect(testApp).toBeDefined(); |
| 54 | + |
| 55 | + // Assert test-app properties |
| 56 | + expect(testApp).toMatchObject({ |
| 57 | + application_id: 'test-app', |
| 58 | + name: 'test-app', |
| 59 | + regulatory_classes: expect.arrayContaining([expect.any(String)]), |
| 60 | + description: expect.any(String), |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
| 64 | + |
| 65 | +describe('SWR-TSSDK-2.3: Version List Retrieval', () => { |
| 66 | + it('should retrieve all versions for a specified application', async () => { |
| 67 | + const { stdout, exitCode } = await executeCLI(['list-application-versions', 'test-app']); |
| 68 | + |
| 69 | + expect(exitCode).toBe(0); |
| 70 | + |
| 71 | + // Parse the versions from the output |
| 72 | + const output = String(stdout); |
| 73 | + const versionsMatch = output.match(/Application versions for test-app: (\[.*\])/s); |
| 74 | + expect(versionsMatch).toBeTruthy(); |
| 75 | + |
| 76 | + const versions = JSON.parse(versionsMatch![1]) as Array<ApplicationVersion>; |
| 77 | + expect(Array.isArray(versions)).toBe(true); |
| 78 | + expect(versions.length).toBeGreaterThan(0); |
| 79 | + |
| 80 | + // Verify each version has required properties |
| 81 | + versions.forEach(version => { |
| 82 | + expect(version).toHaveProperty('number'); |
| 83 | + expect(version).toHaveProperty('released_at'); |
| 84 | + expect(version.number).toMatch(/\d+\.\d+\.\d+/); |
| 85 | + expect(version.released_at).toMatch( |
| 86 | + /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])T([01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?Z$/ |
| 87 | + ); |
| 88 | + }); |
| 89 | + }); |
| 90 | +}); |
0 commit comments