forked from asyncapi/website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* change url to asyncapi.com * add test script to package.json
- Loading branch information
1 parent
22746a9
commit aabef87
Showing
3 changed files
with
28 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,38 +3,49 @@ import { Context } from "https://edge-bootstrap.netlify.app/v1/index.ts"; | |
import * as mf from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts"; | ||
|
||
const metricURL = "https://metric-api.eu.newrelic.com/metric/v1"; | ||
|
||
const validRequests = [ | ||
{ | ||
requestURL: "http://localhost:8888/definitions/2.4.0/info.json", | ||
requestURL: "https://asyncapi.com/definitions/2.4.0/info.json", | ||
responseURL: | ||
"https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/definitions/2.4.0/info.json", | ||
}, | ||
{ | ||
requestURL: "http://localhost:8888/schema-store/2.5.0-without-$id.json", | ||
requestURL: "https://asyncapi.com/schema-store/2.5.0-without-$id.json", | ||
responseURL: | ||
"https://raw.githubusercontent.com/asyncapi/spec-json-schemas/master/schemas/2.5.0-without-$id.json", | ||
}, | ||
]; | ||
|
||
const invalidRequests = [ | ||
{ | ||
requestURL: "http://localhost:8888/definitions/asyncapi.yaml", | ||
requestURL: "https://asyncapi.com/definitions/asyncapi.yaml", | ||
}, | ||
{ | ||
requestURL: "http://localhost:8888/schema-store/2.4.0.JSON", | ||
requestURL: "https://asyncapi.com/schema-store/2.4.0.JSON", | ||
}, | ||
{ | ||
requestURL: "https://asyncapi.com/foobar", | ||
} | ||
]; | ||
|
||
const context = { | ||
next: () => {}, | ||
log: () => {}, | ||
}; | ||
|
||
let metricCalls = 0; | ||
|
||
function setup() { | ||
mf.install(); | ||
|
||
mf.mock("*", (req) => { | ||
console.log(req.url); | ||
|
||
if( req.url === metricURL ) { | ||
metricCalls++; | ||
} | ||
|
||
const body = { | ||
url: req.url, | ||
|
@@ -52,6 +63,8 @@ function setup() { | |
} | ||
|
||
Deno.test("serve-definitions test for validRequests", async () => { | ||
metricCalls = 0; | ||
|
||
setup(); | ||
|
||
for (const entry of validRequests) { | ||
|
@@ -67,10 +80,14 @@ Deno.test("serve-definitions test for validRequests", async () => { | |
console.log("\n"); | ||
} | ||
|
||
assertEquals(metricCalls, validRequests.length); | ||
|
||
mf.uninstall(); | ||
}); | ||
|
||
Deno.test("serve-definitions test for invalidRequests", async () => { | ||
metricCalls = 0; | ||
|
||
setup(); | ||
|
||
for (const entry of invalidRequests) { | ||
|
@@ -81,5 +98,8 @@ Deno.test("serve-definitions test for invalidRequests", async () => { | |
assertEquals(response, undefined); | ||
} | ||
|
||
// No metrics should be sent for invalid requests | ||
assertEquals(metricCalls, 0); | ||
|
||
mf.uninstall(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters