Skip to content

Commit 7486d9c

Browse files
committed
chore(E2E): add some more test cases
1 parent 9834b61 commit 7486d9c

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

e2e/express.e2e-spec.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ describe("Express RapiDoc", () => {
6969
builder.build(),
7070
);
7171
RapidocModule.setup(RAPIDOC_RELATIVE_URL, app, swaggerDocument, {
72-
// to showcase that in new implementation u can use custom swagger-ui path. Useful when using e.g. webpack
7372
customRapidocAssetsPath: path.resolve(`./node_modules/rapidoc/dist`),
7473
});
7574

@@ -80,6 +79,16 @@ describe("Express RapiDoc", () => {
8079
await app.close();
8180
});
8281

82+
it("should return the same HTML on every consecutive request", async () => {
83+
const response1: Response = await request(app.getHttpServer()).get(
84+
RAPIDOC_RELATIVE_URL,
85+
);
86+
const response2: Response = await request(app.getHttpServer()).get(
87+
RAPIDOC_RELATIVE_URL,
88+
);
89+
expect(response1.text).toEqual(response2.text);
90+
});
91+
8392
it("content type of served json document should be valid", async () => {
8493
const response = await request(app.getHttpServer()).get(
8594
`${RAPIDOC_RELATIVE_URL}/openapi.json`,
@@ -99,6 +108,43 @@ describe("Express RapiDoc", () => {
99108
expect(response.type).toEqual("application/javascript");
100109
expect(response.status).toEqual(200);
101110
});
111+
112+
it("should serve favicon", async () => {
113+
const response = await request(app.getHttpServer()).get(
114+
`${RAPIDOC_RELATIVE_URL}/favicon.png`,
115+
);
116+
117+
expect(response.status).toEqual(200);
118+
expect(response.type).toEqual("image/png");
119+
});
120+
});
121+
122+
describe("served oauth receiver", () => {
123+
const RAPIDOC_RELATIVE_URL = "/rapidoc";
124+
125+
beforeEach(async () => {
126+
const swaggerDocument = SwaggerModule.createDocument(
127+
app,
128+
builder.build(),
129+
);
130+
RapidocModule.setup(RAPIDOC_RELATIVE_URL, app, swaggerDocument);
131+
132+
await app.init();
133+
});
134+
135+
afterEach(async () => {
136+
await app.close();
137+
});
138+
139+
it("should serve oauth receiver", async () => {
140+
const response = await request(app.getHttpServer()).get(
141+
`${RAPIDOC_RELATIVE_URL}/oauth-receiver.html`,
142+
);
143+
144+
expect(response.status).toEqual(200);
145+
expect(response.type).toEqual("text/html");
146+
expect(response.text).toContain("<oauth-receiver />");
147+
});
102148
});
103149

104150
describe("custom documents endpoints", () => {
@@ -218,6 +264,7 @@ describe("Express RapiDoc", () => {
218264
const CUSTOM_SITE_TITLE = "Foo";
219265
const CUSTOM_CSS_URL = "/foo.css";
220266
const CUSTOM_URL = "/custom";
267+
const CUSTOM_LOGO = "/logo.png";
221268

222269
beforeEach(async () => {
223270
const swaggerDocument = SwaggerModule.createDocument(
@@ -232,13 +279,18 @@ describe("Express RapiDoc", () => {
232279
customFavIcon: CUSTOM_FAVICON,
233280
customSiteTitle: CUSTOM_SITE_TITLE,
234281
customCssUrl: CUSTOM_CSS_URL,
282+
customLogo: CUSTOM_LOGO,
235283
patchDocumentOnRequest: (req, res, document) => ({
236284
...document,
237285
info: {
238286
...document.info,
239287
description: (req as Record<string, any>).query.description,
240288
},
241289
}),
290+
rapidocOptions: {
291+
showHeader: false,
292+
apiKeyName: "x-api-key",
293+
},
242294
});
243295

244296
await app.init();
@@ -290,6 +342,15 @@ describe("Express RapiDoc", () => {
290342
);
291343
});
292344

345+
it("should include the custom logo", async () => {
346+
const response: Response = await request(app.getHttpServer()).get(
347+
CUSTOM_URL,
348+
);
349+
expect(response.text).toContain(
350+
`<img slot="logo" src='${CUSTOM_LOGO}' style="height:36px;width:36px;margin-left:5px" />`,
351+
);
352+
});
353+
293354
it("should patch the OpenAPI document", async function () {
294355
const response: Response = await request(app.getHttpServer()).get(
295356
`${CUSTOM_URL}?description=Custom%20Swagger%20description%20passed%20by%20query%20param`,

e2e/fastify.e2e-spec.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe("Fastify RapiDoc", () => {
7171
builder.build(),
7272
);
7373
RapidocModule.setup(RAPIDOC_RELATIVE_URL, app, swaggerDocument, {
74-
// to showcase that in new implementation u can use custom swagger-ui path. Useful when using e.g. webpack
7574
customRapidocAssetsPath: path.resolve(`./node_modules/rapidoc/dist`),
7675
});
7776

@@ -83,6 +82,16 @@ describe("Fastify RapiDoc", () => {
8382
await app.close();
8483
});
8584

85+
it("should return the same HTML on every consecutive request", async () => {
86+
const response1: Response = await request(app.getHttpServer()).get(
87+
RAPIDOC_RELATIVE_URL,
88+
);
89+
const response2: Response = await request(app.getHttpServer()).get(
90+
RAPIDOC_RELATIVE_URL,
91+
);
92+
expect(response1.text).toEqual(response2.text);
93+
});
94+
8695
it("content type of served json document should be valid", async () => {
8796
const response = await request(app.getHttpServer()).get(
8897
`${RAPIDOC_RELATIVE_URL}/openapi.json`,
@@ -102,6 +111,44 @@ describe("Fastify RapiDoc", () => {
102111
expect(response.type).toEqual("application/javascript");
103112
expect(response.status).toEqual(200);
104113
});
114+
115+
it("should serve favicon", async () => {
116+
const response = await request(app.getHttpServer()).get(
117+
`${RAPIDOC_RELATIVE_URL}/favicon.png`,
118+
);
119+
120+
expect(response.status).toEqual(200);
121+
expect(response.type).toEqual("image/png");
122+
});
123+
});
124+
125+
describe("served oauth receiver", () => {
126+
const RAPIDOC_RELATIVE_URL = "/rapidoc";
127+
128+
beforeEach(async () => {
129+
const swaggerDocument = SwaggerModule.createDocument(
130+
app,
131+
builder.build(),
132+
);
133+
RapidocModule.setup(RAPIDOC_RELATIVE_URL, app, swaggerDocument);
134+
135+
await app.init();
136+
await app.getHttpAdapter().getInstance().ready();
137+
});
138+
139+
afterEach(async () => {
140+
await app.close();
141+
});
142+
143+
it("should serve oauth receiver", async () => {
144+
const response = await request(app.getHttpServer()).get(
145+
`${RAPIDOC_RELATIVE_URL}/oauth-receiver.html`,
146+
);
147+
148+
expect(response.status).toEqual(200);
149+
expect(response.type).toEqual("text/html");
150+
expect(response.text).toContain("<oauth-receiver />");
151+
});
105152
});
106153

107154
describe("custom documents endpoints", () => {
@@ -223,6 +270,7 @@ describe("Fastify RapiDoc", () => {
223270
const CUSTOM_SITE_TITLE = "Foo";
224271
const CUSTOM_CSS_URL = "/foo.css";
225272
const CUSTOM_URL = "/custom";
273+
const CUSTOM_LOGO = "/logo.png";
226274

227275
beforeEach(async () => {
228276
const swaggerDocument = SwaggerModule.createDocument(
@@ -237,13 +285,18 @@ describe("Fastify RapiDoc", () => {
237285
customFavIcon: CUSTOM_FAVICON,
238286
customSiteTitle: CUSTOM_SITE_TITLE,
239287
customCssUrl: CUSTOM_CSS_URL,
288+
customLogo: CUSTOM_LOGO,
240289
patchDocumentOnRequest: (req, res, document) => ({
241290
...document,
242291
info: {
243292
...document.info,
244293
description: (req as Record<string, any>).query.description,
245294
},
246295
}),
296+
rapidocOptions: {
297+
showHeader: false,
298+
apiKeyName: "x-api-key",
299+
},
247300
});
248301

249302
await app.init();
@@ -296,6 +349,15 @@ describe("Fastify RapiDoc", () => {
296349
);
297350
});
298351

352+
it("should include the custom logo", async () => {
353+
const response: Response = await request(app.getHttpServer()).get(
354+
CUSTOM_URL,
355+
);
356+
expect(response.text).toContain(
357+
`<img slot="logo" src='${CUSTOM_LOGO}' style="height:36px;width:36px;margin-left:5px" />`,
358+
);
359+
});
360+
299361
it("should patch the OpenAPI document", async function () {
300362
const response: Response = await request(app.getHttpServer()).get(
301363
`${CUSTOM_URL}?description=Custom%20Swagger%20description%20passed%20by%20query%20param`,

e2e/jest.config.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module.exports = {
1212
coveragePathIgnorePatterns: [
1313
"<rootDir>/node_modules/",
1414
"<rootDir>/e2e/",
15+
"<rootDir>/e2e-coverage/",
16+
"<rootDir>/coverage/",
17+
"<rootDir>/dist/",
18+
"<rootDir>/lib/",
1519
".dto.(t|j)s",
1620
".interface.(t|j)s",
1721
],

0 commit comments

Comments
 (0)