mirror of
https://github.com/directus/directus.git
synced 2026-01-25 10:08:04 -05:00
* Remove UTC conversion from date, time and datetime fields * Fix mysql / maria timestamps when not in UTC timezone * Add sequential tests with node timezone change * Increase connection attempt check * Add error catching in tests flow setup * Check for server connectivity * Fix promises * Fix timestamp inconsistencies * Revert to previously used parseISO * Ensure database and directus connection * Add another timezone to test positive and negative GMT * Set local server hostname to localhost * Add tests for SQLite * Use notNullable primary key * Revert connection testing sleep duration * Fix nested transactions on SQLite * Increase MSSQL request timeout * Add type override flag for SQLite * Remove commented code * Add type override flags for Oracle * Updated test file path * Increase test servers launch timeout * Increase test servers launch timeout * Update format of tests * Fix typo * Increase test timeout for CockroachDB * Add type overrides when creating fields through collections service * Remove time field type conversion for Oracle * Update collections list in test * Remove check for time field in Oracle * Add missing continue... * Remove database override * Add note for SQLite * Rename flags and extract shared util * Abstract remaining DB specific checks * Revert flags renaming except renaming of test files * Use date helper to add field flag * Move field date typecasting upstream * Use timestamp helper for date-created and date-updated * Fix tests * Remove unused vars * Add tests for date-created * Increase connection attempt count * Fix test for mariadb * Increase allowable difference to account for delays * Add tests for date-updated * Fix tests again for mariadb * Add date helpers post merge Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
106 lines
2.5 KiB
TypeScript
106 lines
2.5 KiB
TypeScript
import knex, { Knex } from 'knex';
|
|
import { MockClient, Tracker, getTracker } from 'knex-mock-client';
|
|
import { PayloadService } from '../../src/services';
|
|
import { getHelpers, Helpers } from '../../src/database/helpers';
|
|
|
|
jest.mock('../../src/database/index', () => {
|
|
return { getDatabaseClient: jest.fn().mockReturnValue('postgres') };
|
|
});
|
|
jest.requireMock('../../src/database/index');
|
|
|
|
describe('Integration Tests', () => {
|
|
let db: jest.Mocked<Knex>;
|
|
let tracker: Tracker;
|
|
|
|
beforeAll(async () => {
|
|
db = knex({ client: MockClient }) as jest.Mocked<Knex>;
|
|
tracker = getTracker();
|
|
});
|
|
|
|
afterEach(() => {
|
|
tracker.reset();
|
|
});
|
|
|
|
describe('Services / PayloadService', () => {
|
|
describe('transformers', () => {
|
|
let service: PayloadService;
|
|
let helpers: Helpers;
|
|
|
|
beforeEach(() => {
|
|
service = new PayloadService('test', {
|
|
knex: db,
|
|
schema: { collections: {}, relations: [] },
|
|
});
|
|
helpers = getHelpers(db);
|
|
});
|
|
|
|
describe('csv', () => {
|
|
it('Returns undefined for illegal values', async () => {
|
|
const result = await service.transformers['cast-csv']({
|
|
value: 123,
|
|
action: 'read',
|
|
payload: {},
|
|
accountability: { role: null },
|
|
specials: [],
|
|
helpers,
|
|
});
|
|
|
|
expect(result).toBe(undefined);
|
|
});
|
|
|
|
it('Returns [] for empty strings', async () => {
|
|
const result = await service.transformers['cast-csv']({
|
|
value: '',
|
|
action: 'read',
|
|
payload: {},
|
|
accountability: { role: null },
|
|
specials: [],
|
|
helpers,
|
|
});
|
|
|
|
expect(result).toMatchObject([]);
|
|
});
|
|
|
|
it('Splits the CSV string', async () => {
|
|
const result = await service.transformers['cast-csv']({
|
|
value: 'test,directus',
|
|
action: 'read',
|
|
payload: {},
|
|
accountability: { role: null },
|
|
specials: [],
|
|
helpers,
|
|
});
|
|
|
|
expect(result).toMatchObject(['test', 'directus']);
|
|
});
|
|
|
|
it('Saves array values as joined string', async () => {
|
|
const result = await service.transformers['cast-csv']({
|
|
value: ['test', 'directus'],
|
|
action: 'create',
|
|
payload: {},
|
|
accountability: { role: null },
|
|
specials: [],
|
|
helpers,
|
|
});
|
|
|
|
expect(result).toBe('test,directus');
|
|
});
|
|
|
|
it('Saves string values as is', async () => {
|
|
const result = await service.transformers['cast-csv']({
|
|
value: 'test,directus',
|
|
action: 'create',
|
|
payload: {},
|
|
accountability: { role: null },
|
|
specials: [],
|
|
helpers,
|
|
});
|
|
|
|
expect(result).toBe('test,directus');
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|