soapbox/src/reducers/instance.test.ts

55 wiersze
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
2024-11-10 03:18:55 +00:00
import { ADMIN_CONFIG_UPDATE_REQUEST } from 'soapbox/actions/admin.ts';
2024-11-10 03:18:55 +00:00
import reducer from './instance.ts';
2020-06-10 01:08:07 +00:00
describe('instance reducer', () => {
it('should return the initial state', () => {
const result = reducer(undefined, {} as any);
2022-03-09 05:25:30 +00:00
const expected = {
description_limit: 1500,
2022-03-09 05:25:30 +00:00
configuration: {
chats: {
2023-02-08 20:07:31 +00:00
max_characters: 5000,
max_media_attachments: 1,
},
2022-03-09 05:25:30 +00:00
statuses: {
max_characters: 500,
2022-01-31 23:52:12 +00:00
max_media_attachments: 4,
2022-03-09 05:25:30 +00:00
},
polls: {
max_options: 4,
max_characters_per_option: 25,
min_expiration: 300,
max_expiration: 2629746,
2022-03-09 05:25:30 +00:00
},
},
2021-01-18 20:14:08 +00:00
version: '0.0.0',
2022-03-09 05:25:30 +00:00
};
2023-09-24 01:41:24 +00:00
expect(result).toMatchObject(expected);
2020-06-10 01:08:07 +00:00
});
2023-10-09 03:18:34 +00:00
describe('ADMIN_CONFIG_UPDATE_REQUEST', async () => {
const { configs } = await import('soapbox/__fixtures__/pleroma-admin-config.json');
2022-03-20 23:41:47 +00:00
it('imports the configs', () => {
const action = {
type: ADMIN_CONFIG_UPDATE_REQUEST,
configs,
};
// The normalizer has `registrations: closed` by default
const state = reducer(undefined, {} as any);
2022-03-20 23:41:47 +00:00
expect(state.registrations).toBe(false);
// After importing the configs, registration will be open
// @ts-ignore don't know why the type is not working
2022-03-20 23:41:47 +00:00
const result = reducer(state, action);
expect(result.registrations).toBe(true);
});
});
2020-06-10 01:08:07 +00:00
});