Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions __tests__/respect/local-json-server/local-json-server.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { spawn } from 'child_process';
import { getParams, getCommandOutput } from '../utils';
import { join } from 'path';
import * as fs from 'fs';

const dbPath = join(__dirname, 'fake-db.json');

describe('local-json-server', () => {
let serverProcess: any;
let originalData: string | undefined;

beforeAll(async () => {
// Start json-server
serverProcess = spawn('npm', ['run', 'json-server'], { detached: true });

// Store original state of fake-bd.json
originalData = fs.readFileSync(dbPath, 'utf8');
});

afterAll(() => {
// Kill the process group to ensure child processes are cleaned up
process.kill(-serverProcess.pid);

// Restore original state
if (originalData) {
fs.writeFileSync(dbPath, originalData);
}
});

test('local-json-server test case', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should replace values in the request body 1`] = `
"────────────────────────────────────────────────────────────────────────────────

Running workflow replacements.arazzo.yaml / replacements

✓ GET /special-events/{eventId} - step first-step

    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/special-events/dad4bce8-f5cb-4078-a211-995864315e39
    Request Headers:
      accept: application/json, application/problem+json
      authorization: Basic Og==


    Response status code: 200
    Response time: <test> ms
    Response Body:
      {
       "eventId": "6744a0da-4121-49cd-8479-f8cc20526495",
       "name": "Time Traveler Tea Party",
       "location": "Temporal Tearoom",
       "eventDescription": "Sip tea with important historical figures.",
       "dates": [
       "2023-11-18",
       "2023-11-25",
       "2023-12-02"
       ],
       "price": 60
      }

    ✓ status code check - $statusCode in [200, 400, 404]
    ✓ content-type check
    ✓ schema check

✓ POST /tickets - step second-step

    Request URL: https://redocly.com/_mock/demo/openapi/museum-api/tickets
    Request Headers:
      content-type: application/json
      accept: application/json, application/problem+json
      authorization: Basic Og==
    Request Body:
      {
       "eventId": "my-custom-event-id",
       "name": "Time Traveler Tea Party",
       "location": "Time Traveler Tea Party",
       "eventDescription": "Sip tea with important historical figures.",
       "dates": [
       "2025-01-01"
       ],
       "price": 60
      }


    Response status code: 400
    Response time: <test> ms
    Response Body:
      {
       "type": "object",
       "title": "Error validating body. data must have required property 'ticketType', data must have required property 'ticketDate', data must have required property 'email', data/eventId must match format \\"uuid\\""
      }

    ✓ status code check - $statusCode in [201, 400, 404]
    ✓ content-type check
    ✓ schema check


  Summary for replacements.arazzo.yaml

  Workflows: 1 passed, 1 total
  Steps: 2 passed, 2 total
  Checks: 6 passed, 6 total
  Time: <test>ms


┌──────────────────────────────────────────────────────────────────┬────────────┬─────────┬─────────┬──────────┐
│ Filename │ Workflows │ Passed │ Failed │ Warnings │
├──────────────────────────────────────────────────────────────────┼────────────┼─────────┼─────────┼──────────┤
│ ✓ replacements.arazzo.yaml │ 1 │ 1 │ - │ - │
└──────────────────────────────────────────────────────────────────┴────────────┴─────────┴─────────┴──────────┘


"
`;
Loading
Loading