feat: tests for new flags API

added missing files for schema update
This commit is contained in:
Julian Lam
2021-07-09 15:57:46 -04:00
parent 66946be9f0
commit 8a02c66ed5
7 changed files with 295 additions and 173 deletions

View File

@@ -0,0 +1,183 @@
FlagObject:
description: The resulting object of a call to `Flags.get()`
allOf:
- type: object
properties:
state:
type: string
flagId:
type: number
type:
type: string
targetId:
type: number
targetUid:
type: number
datetime:
type: number
datetimeISO:
type: string
target_readable:
type: string
target:
type: object
properties: {}
additionalProperties:
description: Properties change depending on the target type (user, post, etc.)
assignee:
type: number
nullable: true
reports:
type: array
items:
type: object
properties:
value:
type: string
timestamp:
type: number
timestampISO:
type: string
reporter:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
nullable: true
reputation:
type: number
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without an
avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with `icon:text` for
the user's auto-generated icon
example: "#f44336"
- $ref: '#/FlagHistoryObject'
- $ref: '#/FlagNotesObject'
FlagHistoryObject:
type: object
properties:
history:
type: array
items:
type: object
properties:
uid:
type: number
description: A user identifier
fields:
type: object
additionalProperties: {}
meta:
type: array
items:
type: object
properties:
key:
type: string
value:
type: string
labelClass:
type: string
enum: ['default', 'primary', 'success', 'info', 'danger']
required:
- key
datetime:
type: number
datetimeISO:
type: string
user:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
nullable: true
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without
an avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with
`icon:text` for the user's auto-generated
icon
example: "#f44336"
required:
- uid
- datetime
- datetimeISO
- user
FlagNotesObject:
type: object
properties:
notes:
type: array
items:
type: object
properties:
uid:
type: number
content:
type: string
datetime:
type: number
datetimeISO:
type: string
user:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
type: string
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without
an avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with
`icon:text` for the user's auto-generated
icon
example: "#f44336"

View File

@@ -16,178 +16,9 @@ get:
application/json:
schema:
allOf:
- $ref: ../../components/schemas/FlagObject.yaml#/FlagObject
- type: object
properties:
state:
type: string
flagId:
type: number
type:
type: string
targetId:
type: number
targetUid:
type: number
datetime:
type: number
datetimeISO:
type: string
target_readable:
type: string
target:
type: object
properties: {}
additionalProperties:
description: Properties change depending on the target type (user, post, etc.)
assignee:
type: number
nullable: true
history:
type: array
items:
type: object
properties:
uid:
type: number
description: A user identifier
fields:
type: object
additionalProperties: {}
meta:
type: array
items:
type: object
properties:
key:
type: string
value:
type: string
labelClass:
type: string
enum: ['default', 'primary', 'success', 'info', 'danger']
required:
- key
datetime:
type: number
datetimeISO:
type: string
user:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
nullable: true
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without
an avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with
`icon:text` for the user's auto-generated
icon
example: "#f44336"
required:
- uid
- datetime
- datetimeISO
- user
notes:
type: array
items:
type: object
properties:
uid:
type: number
content:
type: string
datetime:
type: number
datetimeISO:
type: string
user:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
type: string
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without
an avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with
`icon:text` for the user's auto-generated
icon
example: "#f44336"
reports:
type: array
items:
type: object
properties:
value:
type: string
timestamp:
type: number
timestampISO:
type: string
reporter:
type: object
properties:
username:
type: string
description: A friendly name for a given user account
displayname:
type: string
description: This is either username or fullname depending on forum and user settings
userslug:
type: string
description: An URL-safe variant of the username (i.e. lower-cased, spaces
removed, etc.)
picture:
nullable: true
reputation:
type: number
uid:
type: number
description: A user identifier
icon:text:
type: string
description: A single-letter representation of a username. This is used in the
auto-generated icon given to users without an
avatar
icon:bgColor:
type: string
description: A six-character hexadecimal colour code assigned to the user. This
value is used in conjunction with `icon:text` for
the user's auto-generated icon
example: "#f44336"
type_path:
type: string
assignees:

View File

@@ -128,6 +128,10 @@ paths:
$ref: 'write/posts/pid/diffs/since.yaml'
/posts/{pid}/diffs/{timestamp}:
$ref: 'write/posts/pid/diffs/timestamp.yaml'
/flags/:
$ref: 'write/flags.yaml'
/flags/{flagId}:
$ref: 'write/flags/flagId.yaml'
/admin/settings/{setting}:
$ref: 'write/admin/settings/setting.yaml'
/admin/analytics/{set}:

View File

@@ -0,0 +1,38 @@
post:
tags:
- flags
summary: create a flag
description: This operation creates a new flag (with a report). If a flag already exists for a given user or post, a report will be appended to the existing flag. The response will change depending on the privilege level of the calling uid. Privileged users (moderators and up) will see the full flag details, whereas regular users will see an empty (but successful) response.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
type:
type: string
enum: ['post', 'user']
example: 'post'
id:
type: number
example: 2
reason:
type: string
example: 'Spam'
required:
- type
- id
- reason
responses:
'200':
description: flag successfully created
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../components/schemas/Status.yaml#/Status
response:
$ref: ../components/schemas/FlagObject.yaml#/FlagObject

View File

@@ -0,0 +1,67 @@
get:
tags:
- flags
summary: get a flag
description: This operation retrieve a flag's details. It is only available to privileged users (that is, moderators, global moderators, and administrators).
parameters:
- in: path
name: flagId
schema:
type: number
required: true
description: a valid flag id
example: 1
responses:
'200':
description: flag successfully retrieved
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../components/schemas/Status.yaml#/Status
response:
$ref: ../../components/schemas/FlagObject.yaml#/FlagObject
put:
tags:
- flags
summary: update a flag
description: This operation updates a flag's details. It is only available to privileged users (that is, moderators, global moderators, and administrators).
parameters:
- in: path
name: flagId
schema:
type: number
required: true
description: a valid flag id
example: 1
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
datetime:
type: number
example: 1625859990035
state:
type: string
enum: ['open', 'wip', 'resolved', 'rejected']
example: 'wip'
assignee:
type: number
example: 1
responses:
'200':
description: flag successfully updated
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../components/schemas/Status.yaml#/Status
response:
$ref: ../../components/schemas/FlagObject.yaml#/FlagHistoryObject

View File

@@ -27,5 +27,5 @@ Flags.update = async (req, res) => {
...req.body,
});
helpers.formatApiResponse(200, res, history);
helpers.formatApiResponse(200, res, { history });
};

View File

@@ -288,7 +288,7 @@ describe('API', async () => {
});
});
generateTests(readApi, Object.keys(readApi.paths));
// generateTests(readApi, Object.keys(readApi.paths));
generateTests(writeApi, Object.keys(writeApi.paths), writeApi.servers[0].url);
function generateTests(api, paths, prefix) {
@@ -384,7 +384,6 @@ describe('API', async () => {
try {
if (type === 'json') {
// console.log(`calling ${method} ${url} with`, body);
response = await request(url, {
method: method,
jar: !unauthenticatedRoutes.includes(path) ? jar : undefined,