Skip to content

Commit

Permalink
Test for expected behaviour #93
Browse files Browse the repository at this point in the history
  • Loading branch information
oliyh committed Aug 26, 2020
1 parent a3695b8 commit 74b6d50
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/test-resources/openapi2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "1"
},
"paths": {
"/project/{projectKey}": {
"get": {
"summary": "Get specific values from a configuration for a specific project",
"operationId": "getProjectConfiguration",
"parameters": [
{
"name": "projectId",
"in": "path",
"description": "Project ID",
"required": true,
"schema": {
"type": "string",
"format": "string"
}
},
{
"name": "key",
"in": "query",
"description": "Obtains values corresponding to these keys from a project's configuration",
"schema": {
"type": "string",
"format": "string"
}
}
],
"responses": {
"200": {
"description": "Configuration for the specified project",
"content": {
"application/json": {
"schema": {
"type": "string",
"format": "string"
}
}
}
},
"403": {
"description": "Refusing access to requested resource, perhaps due to insufficient privilege"
},
"404": {
"description": "Requested resource was not found"
}
}
}
}
}
}
25 changes: 25 additions & 0 deletions core/test/martian/openapi_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@
(->> (filter #(= (:route-name %) :update-pet)))
first
(select-keys [:consumes :produces]))))))

(deftest openapi-two-test
(testing "parses parameters which are different somehow"
(is (= {:description nil,
:method :get,
:produces ["application/json"],
:path-schema {:projectId s/Str},
:query-schema {(s/optional-key :key) s/Str},
:form-schema {},
:path-parts ["/project/" :projectKey],
:headers-schema {},
:consumes [nil],
:summary "Get specific values from a configuration for a specific project",
:body-schema nil,
:route-name :get-project-configuration,
:response-schemas
[{:status (s/eq 200), :body s/Str}
{:status (s/eq 403), :body nil}
{:status (s/eq 404), :body nil}]}
(-> (parse-string (slurp (io/resource "openapi2.json")))
(openapi->handlers {:encodes ["application/json" "application/octet-stream"]
:decodes ["application/json" "application/octet-stream"]})
(->> (filter #(= (:route-name %) :get-project-configuration)))
first
(dissoc :openapi-definition))))))

0 comments on commit 74b6d50

Please sign in to comment.