Skip to content

Commit

Permalink
test: add tests for generating release description
Browse files Browse the repository at this point in the history
  • Loading branch information
shenbenson committed Dec 17, 2024
1 parent 8438610 commit 6a07b0b
Show file tree
Hide file tree
Showing 15 changed files with 737 additions and 1 deletion.
23 changes: 23 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Pull Request

on:
pull_request:
paths:
- scripts/api-diff.js
- tests/**

jobs:
test-api-diff:
name: Run API Diff Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Run tests
run: node --test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v20.10.0
75 changes: 75 additions & 0 deletions tests/fixtures/modified-component/current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"openapi": "3.0.3",
"info": {
"title": "Test API",
"description": "A sample API to for testing",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user": {
"post": {
"summary": "Create a new user profile",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewUser"
}
}
}
},
"responses": {
"201": {
"description": "User created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"username": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"NewUser": {
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"username": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/modified-component/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Modified
- [POST] `/user`
- `NewUser` modified in requestBody
- `User` modified in requestBody, responses
75 changes: 75 additions & 0 deletions tests/fixtures/modified-component/previous.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"openapi": "3.0.3",
"info": {
"title": "Test API",
"description": "A sample API to for testing",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user": {
"post": {
"summary": "Create a new user profile",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewUser"
}
}
}
},
"responses": {
"201": {
"description": "User created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"NewUser": {
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}
}
75 changes: 75 additions & 0 deletions tests/fixtures/modified-route-and-method/current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"openapi": "3.0.3",
"info": {
"title": "Test API",
"description": "A sample API to for testing",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user": {
"post": {
"summary": "Create a new user",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewUser"
}
}
}
},
"responses": {
"201": {
"description": "User created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"NewUser": {
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/modified-route-and-method/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Modified
- [POST] `/user`
- responses
- summary
75 changes: 75 additions & 0 deletions tests/fixtures/modified-route-and-method/previous.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"openapi": "3.0.3",
"info": {
"title": "Test API",
"description": "A sample API to for testing",
"version": "1.0.0"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user": {
"post": {
"summary": "Create a new user profile",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewUser"
}
}
}
},
"responses": {
"201": {
"description": "User created successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"NewUser": {
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}
}
Loading

0 comments on commit 6a07b0b

Please sign in to comment.