Skip to content

Node.js based forum software built for the modern web

fix: all tests, wrap up work

Julian Lamf416dc177abe
diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml
index c6e3afcb99..f33624b521 100644
--- a/public/openapi/read.yaml
+++ b/public/openapi/read.yaml
@@ -54,6 +54,8 @@ tags:
description: Disparate method of categorizing topics
- name: shorthand
description: Convenience and utility routes for accessing other part of the API
+ - name: other
+ description: Other one-off routes that do not fit in a section of their own
paths:
/api/:
$ref: 'read/index.yaml'
@@ -177,6 +179,8 @@ paths:
$ref: 'read/categories.yaml'
"/api/categories/{cid}/moderators":
$ref: 'read/categories/cid/moderators.yaml'
+ "/api/topic/{topic_id}/{slug}":
+ $ref: 'read/topic/topic_id.yaml'
"/api/topic/{topic_id}/{slug}/{post_index}":
$ref: 'read/topic/topic_id.yaml'
/api/recent:
@@ -203,6 +207,8 @@ paths:
$ref: 'read/register/complete.yaml'
"/api/confirm/{code}":
$ref: 'read/confirm/code.yaml'
+ /api/tos:
+ $ref: 'read/tos.yaml'
/api/search:
$ref: 'read/search.yaml'
"/api/reset":
@@ -231,6 +237,8 @@ paths:
$ref: 'read/popular.yaml'
/api/top:
$ref: 'read/top.yaml'
+ "/api/category/{category_id}/{slug}":
+ $ref: 'read/category/category_id.yaml'
"/api/category/{category_id}/{slug}/{topic_index}":
$ref: 'read/category/category_id.yaml'
/api/self:
@@ -300,4 +308,6 @@ paths:
"/api/groups/{slug}":
$ref: 'read/groups/slug.yaml'
"/api/groups/{slug}/members":
- $ref: 'read/groups/slug/members.yaml'
\ No newline at end of file
+ $ref: 'read/groups/slug/members.yaml'
+ /api/outgoing:
+ $ref: 'read/outgoing.yaml'
\ No newline at end of file
diff --git a/public/openapi/read/admin/groups/groupname/csv.yaml b/public/openapi/read/admin/groups/groupname/csv.yaml
index 43a5bf8e59..e774a1b4a1 100644
--- a/public/openapi/read/admin/groups/groupname/csv.yaml
+++ b/public/openapi/read/admin/groups/groupname/csv.yaml
@@ -9,6 +9,12 @@ get:
type: string
required: true
example: /admin/manage/groups
+ - in: path
+ name: groupname
+ schema:
+ type: string
+ required: true
+ example: registered-users
responses:
"200":
description: "A CSV file containing all users in the group"
diff --git a/public/openapi/read/confirm/code.yaml b/public/openapi/read/confirm/code.yaml
index d066ede5f9..c3e75649b8 100644
--- a/public/openapi/read/confirm/code.yaml
+++ b/public/openapi/read/confirm/code.yaml
@@ -18,5 +18,4 @@ get:
description: Translation key for client-side localisation
required:
- title
- - $ref: ../../components/schemas/Breadcrumbs.yaml#/Breadcrumbs
- $ref: ../../components/schemas/CommonProps.yaml#/CommonProps
\ No newline at end of file
diff --git a/public/openapi/read/outgoing.yaml b/public/openapi/read/outgoing.yaml
new file mode 100644
index 0000000000..ffde8242bf
--- /dev/null
+++ b/public/openapi/read/outgoing.yaml
@@ -0,0 +1,29 @@
+get:
+ tags:
+ - other
+ summary: Warn before navigating externally
+ parameters:
+ - in: query
+ name: url
+ schema:
+ type: string
+ description: URL of the page to warn the user about
+ example: https://example.org
+ description: This route presents a warning to a user notifying them that the page they are about to view is hosted externally. They then have the option of continuing onwards or going back to where they came from.
+ responses:
+ "200":
+ description: Warning page presented
+ content:
+ application/json:
+ schema:
+ allOf:
+ - type: object
+ properties:
+ outgoing:
+ type: string
+ description: Escaped URL of the page to navigate to
+ title:
+ description: The page title
+ type: string
+ - $ref: ../components/schemas/Breadcrumbs.yaml#/Breadcrumbs
+ - $ref: ../components/schemas/CommonProps.yaml#/CommonProps
\ No newline at end of file
diff --git a/public/openapi/read/tos.yaml b/public/openapi/read/tos.yaml
new file mode 100644
index 0000000000..1c66f4bdc9
--- /dev/null
+++ b/public/openapi/read/tos.yaml
@@ -0,0 +1,18 @@
+get:
+ tags:
+ - authentication
+ summary: Get forum terms of service
+ description: This route allows you to view the forum terms of service.
+ responses:
+ "200":
+ description: Terms of service retrieved.
+ content:
+ application/json:
+ schema:
+ allOf:
+ - type: object
+ properties:
+ termsOfUse:
+ type: string
+ description: Full text of the configured terms of service/terms of use.
+ - $ref: ../components/schemas/CommonProps.yaml#/CommonProps
\ No newline at end of file
diff --git a/test/api.js b/test/api.js
index 3154cd0c14..8e047336b1 100644
--- a/test/api.js
+++ b/test/api.js
@@ -100,6 +100,7 @@ describe('API', async () => {
}],
});
meta.config.allowTopicsThumbnail = 1;
+ meta.config.termsOfUse = 'I, for one, welcome our new test-drive overlords';
// Create a category
const testCategory = await categories.create({ name: 'test' });
@@ -225,8 +226,8 @@ describe('API', async () => {
});
});
- // generateTests(readApi, Object.keys(readApi.paths));
- // generateTests(writeApi, Object.keys(writeApi.paths), writeApi.servers[0].url);
+ generateTests(readApi, Object.keys(readApi.paths));
+ generateTests(writeApi, Object.keys(writeApi.paths), writeApi.servers[0].url);
function generateTests(api, paths, prefix) {
// Iterate through all documented paths, make a call to it, and compare the result body with what is defined in the spec
@@ -252,8 +253,9 @@ describe('API', async () => {
return;
}
- const names = (path.match(/{[\w\-_*]+}?/g) || []).map(match => match.slice(1, -1));
- assert(context[method].parameters.map(param => (param.in === 'path' ? param.name : null)).filter(Boolean).every(name => names.includes(name)), `${method.toUpperCase()} ${path} has parameter(s) in path that are not defined in schema`);
+ const pathParams = (path.match(/{[\w\-_*]+}?/g) || []).map(match => match.slice(1, -1));
+ const schemaParams = context[method].parameters.map(param => (param.in === 'path' ? param.name : null)).filter(Boolean);
+ assert(pathParams.every(param => schemaParams.includes(param)), `${method.toUpperCase()} ${path} has path parameters specified but not defined`);
});
it('should have examples when parameters are present', () => {
@@ -333,11 +335,11 @@ describe('API', async () => {
});
} else if (type === 'form') {
response = await new Promise((resolve, reject) => {
- helpers.uploadFile(url, pathLib.join(__dirname, './files/test.png'), {}, jar, csrfToken, function (err, res, body) {
+ helpers.uploadFile(url, pathLib.join(__dirname, './files/test.png'), {}, jar, csrfToken, function (err, res) {
if (err) {
return reject(err);
}
- resolve(body);
+ resolve(res);
});
});
}