enforce uppercase UUIDs for MS SQL (#16691)

* add forced uppercase for UUIDs in MS SQL

* test whether mssql returned uuid is uppercase

* use once just for slight better correctness

* once is actually not enough

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: ian <licitdev@gmail.com>
This commit is contained in:
Brainslug
2022-12-15 06:34:31 +01:00
committed by GitHub
parent 431f95210a
commit bbcf76e030
5 changed files with 44 additions and 4 deletions

View File

@@ -2,11 +2,12 @@ import { NestedDeepQuery } from '@directus/shared/types';
import knex, { Knex } from 'knex';
import { getTracker, MockClient, Tracker } from 'knex-mock-client';
import { cloneDeep } from 'lodash';
import { afterEach, beforeAll, describe, expect, it, vi, MockedFunction } from 'vitest';
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi, MockedFunction } from 'vitest';
import { ItemsService } from '../../src/services';
import { InvalidPayloadException } from '../exceptions';
import { sqlFieldFormatter, sqlFieldList } from '../__utils__/items-utils';
import { systemSchema, userSchema } from '../__utils__/schemas';
import { getDatabaseClient } from '../../src/database/index';
vi.mock('../env', async () => {
const actual = (await vi.importActual('../env')) as { default: Record<string, any> };
@@ -21,7 +22,7 @@ vi.mock('../env', async () => {
vi.mock('../../src/database/index', () => ({
default: vi.fn(),
getDatabaseClient: vi.fn().mockReturnValue('postgres'),
getDatabaseClient: vi.fn(),
}));
vi.mock('../cache', () => ({
@@ -49,6 +50,10 @@ describe('Integration Tests', () => {
tracker = getTracker();
});
beforeEach(() => {
vi.mocked(getDatabaseClient).mockReturnValue('postgres');
});
afterEach(() => {
tracker.reset();
});
@@ -80,6 +85,24 @@ describe('Integration Tests', () => {
expect(response).toBe(item.id);
}
);
it(`the returned UUID primary key for MS SQL should be uppercase`, async () => {
vi.mocked(getDatabaseClient).mockReturnValue('mssql');
const table = schemas.system.tables[0];
const itemsService = new ItemsService(table, {
knex: db,
accountability: { role: 'admin', admin: true },
schema: schemas.system.schema,
});
tracker.on.insert(table).responseOnce(item);
const response = await itemsService.createOne(item, { emitEvents: false });
expect(response).toBe(item.id.toUpperCase());
});
});
describe('readOne', () => {