Skip to content

Commit

Permalink
chore: enhance testing on sdk generation with or without reviver (#1548)
Browse files Browse the repository at this point in the history
## Proposed change

Add a new use case to make sure non light sdk will not throw errors
after generation

## Related issues

- 🐛 Add test cases for
#1537
  • Loading branch information
cpaulve-1A authored Mar 27, 2024
2 parents 1b36e83 + d6b5422 commit 69c9ca3
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/@ama-sdk/create/src/index.it.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
packageManagerRun
} from '@o3r/test-helpers';
import * as fs from 'node:fs';
import { cpSync, mkdirSync, renameSync } from 'node:fs';
import { cpSync, existsSync, mkdirSync, renameSync } from 'node:fs';
import * as path from 'node:path';

const sdkPackageName = '@my-test/sdk';
Expand Down Expand Up @@ -51,16 +51,29 @@ describe('Create new sdk command', () => {

beforeEach(() => {
cpSync(path.join(__dirname, '..', 'testing', 'mocks', 'MOCK_swagger_updated.yaml'), path.join(sdkFolderPath, 'swagger-spec.yml'));
cpSync(path.join(__dirname, '..', 'testing', 'mocks', 'MOCK_DATE_UTILS_swagger.yaml'), path.join(sdkFolderPath, 'swagger-spec-with-date.yml'));
});

test('should generate a full SDK when the specification is provided', () => {
test('should generate a light SDK when the specification is provided', () => {
expect(() =>
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec.yml')]
}, execAppOptions)
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(existsSync(path.join(sdkPackagePath, 'src', 'models', 'base', 'pet', 'pet.reviver.ts'))).toBeFalsy();
});

test('should generate a full SDK when the specification is provided', () => {
expect(() =>
packageManagerCreate({
script: '@ama-sdk',
args: ['typescript', sdkPackageName, '--package-manager', packageManager, '--spec-path', path.join(sdkFolderPath, 'swagger-spec-with-date.yml')]
}, execAppOptions)
).not.toThrow();
expect(() => packageManagerRun({script: 'build'}, { ...execAppOptions, cwd: sdkPackagePath })).not.toThrow();
expect(existsSync(path.join(sdkPackagePath, 'src', 'models', 'base', 'pet', 'pet.reviver.ts'))).toBeTruthy();
});

test('should generate an SDK with no package scope', () => {
Expand Down
111 changes: 111 additions & 0 deletions packages/@ama-sdk/create/testing/mocks/MOCK_DATE_UTILS_swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
swagger: "2.0"
info:
version: 1.0.1
title: Swagger Petstore
license:
name: MIT
host: petstore.swagger.io
basePath: /v1
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
type: integer
format: int32
responses:
"200":
description: A paged array of pets
headers:
x-next:
type: string
description: A link to the next page of responses
schema:
$ref: '#/definitions/Pets'
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
type: string
responses:
"200":
description: Expected response to a valid request
schema:
$ref: '#/definitions/Pets'
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
Pet:
type: "object"
required:
- id
- name
- tag
properties:
nextMeetingAtTheVet:
type: string
format: date
friends:
type: object
allOf:
- $ref: '#/definitions/Pets'
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: '#/definitions/Pet'
Error:
type: "object"
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string

0 comments on commit 69c9ca3

Please sign in to comment.