mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 04:25:13 +00:00
fix unit tests
This commit is contained in:
parent
a6befca845
commit
10d3d9f382
5 changed files with 36 additions and 25 deletions
|
@ -168,13 +168,13 @@ id: 'aidx'
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1)
|
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1)
|
||||||
maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteNoteLength: 100000
|
#maxRemoteNoteLength: 100000
|
||||||
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
||||||
maxAltTextLength: 20000
|
#maxAltTextLength: 20000
|
||||||
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteAltTextLength: 100000
|
#maxRemoteAltTextLength: 100000
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
|
@ -179,6 +179,15 @@ id: 'aidx'
|
||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
|
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1)
|
||||||
|
#maxNoteLength: 3000
|
||||||
|
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
||||||
|
#maxRemoteNoteLength: 100000
|
||||||
|
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
||||||
|
#maxAltTextLength: 20000
|
||||||
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
|
#maxRemoteAltTextLength: 100000
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
||||||
|
|
|
@ -250,14 +250,14 @@ id: 'aidx'
|
||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (maximum: 100000, minimum: 1)
|
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1)
|
||||||
maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (maximum: 100000, minimum: 1)
|
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteNoteLength: 100000
|
#maxRemoteNoteLength: 100000
|
||||||
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
||||||
maxAltTextLength: 20000
|
#maxAltTextLength: 20000
|
||||||
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteAltTextLength: 100000
|
#maxRemoteAltTextLength: 100000
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
|
@ -261,14 +261,14 @@ id: 'aidx'
|
||||||
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
# IP address family used for outgoing request (ipv4, ipv6 or dual)
|
||||||
#outgoingAddressFamily: ipv4
|
#outgoingAddressFamily: ipv4
|
||||||
|
|
||||||
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (maximum: 100000, minimum: 1)
|
# Amount of characters that can be used when writing notes. Longer notes will be rejected. (minimum: 1)
|
||||||
maxNoteLength: 3000
|
#maxNoteLength: 3000
|
||||||
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (maximum: 100000, minimum: 1)
|
# Amount of characters that will be saved for remote notes. Longer notes will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteNoteLength: 100000
|
#maxRemoteNoteLength: 100000
|
||||||
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
# Amount of characters that can be used when writing media descriptions (alt text). Longer descriptions will be rejected. (minimum: 1)
|
||||||
maxAltTextLength: 20000
|
#maxAltTextLength: 20000
|
||||||
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
# Amount of characters that will be saved for remote media descriptions (alt text). Longer descriptions will be truncated to this length. (minimum: 1)
|
||||||
maxRemoteAltTextLength: 100000
|
#maxRemoteAltTextLength: 100000
|
||||||
|
|
||||||
# Proxy for HTTP/HTTPS
|
# Proxy for HTTP/HTTPS
|
||||||
#proxy: http://127.0.0.1:3128
|
#proxy: http://127.0.0.1:3128
|
||||||
|
|
|
@ -5,15 +5,12 @@
|
||||||
|
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
import { readFile } from 'node:fs/promises';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { dirname } from 'node:path';
|
|
||||||
import { describe, test, expect } from '@jest/globals';
|
import { describe, test, expect } from '@jest/globals';
|
||||||
|
import { loadConfig } from '@/config.js';
|
||||||
import { getValidator } from '../../../../../test/prelude/get-api-validator.js';
|
import { getValidator } from '../../../../../test/prelude/get-api-validator.js';
|
||||||
import { paramDef } from './create.js';
|
import { paramDef } from './create.js';
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const config = loadConfig();
|
||||||
const _dirname = dirname(_filename);
|
|
||||||
|
|
||||||
const VALID = true;
|
const VALID = true;
|
||||||
const INVALID = false;
|
const INVALID = false;
|
||||||
|
@ -21,7 +18,12 @@ const INVALID = false;
|
||||||
describe('api:notes/create', () => {
|
describe('api:notes/create', () => {
|
||||||
describe('validation', () => {
|
describe('validation', () => {
|
||||||
const v = getValidator(paramDef);
|
const v = getValidator(paramDef);
|
||||||
const tooLong = readFile(_dirname + '/../../../../../test/resources/misskey.svg', 'utf-8');
|
const tooLong = (limit: number) => {
|
||||||
|
const arr: string[] = [''];
|
||||||
|
arr.length = limit + 1;
|
||||||
|
arr.fill('a');
|
||||||
|
return arr.join('');
|
||||||
|
};
|
||||||
|
|
||||||
test('reject empty', () => {
|
test('reject empty', () => {
|
||||||
const valid = v({ });
|
const valid = v({ });
|
||||||
|
@ -71,8 +73,8 @@ describe('api:notes/create', () => {
|
||||||
.toBe(INVALID);
|
.toBe(INVALID);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('over 500 characters cw', async () => {
|
test('over max characters cw', async () => {
|
||||||
expect(v({ text: 'Body', cw: await tooLong }))
|
expect(v({ text: '', cw: tooLong(config.maxNoteLength) }))
|
||||||
.toBe(INVALID);
|
.toBe(INVALID);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -220,7 +222,7 @@ describe('api:notes/create', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('reject poll with too long choice', async () => {
|
test('reject poll with too long choice', async () => {
|
||||||
expect(v({ poll: { choices: [await tooLong, '2'] } }))
|
expect(v({ poll: { choices: [tooLong(config.maxNoteLength), '2'] } }))
|
||||||
.toBe(INVALID);
|
.toBe(INVALID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue