mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Skip checking of virtual alias fields (#16320)
* Default virtual fields as alias type * Make the condition more verbose instead of defaulting * Remove unnecessary optional chaining * Add tests * Revert to alias defaulting in #d06d62 * Shift condition up
This commit is contained in:
@@ -362,10 +362,10 @@ export class FieldsService {
|
||||
: null;
|
||||
|
||||
if (
|
||||
hookAdjustedField.type &&
|
||||
(hookAdjustedField.type === 'alias' ||
|
||||
this.schema.collections[collection].fields[field.field]?.type === 'alias') &&
|
||||
hookAdjustedField.type &&
|
||||
hookAdjustedField.type !== this.schema.collections[collection].fields[field.field]?.type
|
||||
hookAdjustedField.type !== (this.schema.collections[collection].fields[field.field]?.type ?? 'alias')
|
||||
) {
|
||||
throw new InvalidPayloadException('Alias type cannot be changed');
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
import { CachedTestsSchema, TestsSchema, TestsSchemaVendorValues } from '@query/filter';
|
||||
import { set } from 'lodash';
|
||||
|
||||
export const collectionCountries = 'test_fields_delete_field_countries';
|
||||
export const collectionStates = 'test_fields_delete_field_states';
|
||||
export const collectionCountries = 'test_fields_change_field_countries';
|
||||
export const collectionStates = 'test_fields_change_field_states';
|
||||
|
||||
export type Country = {
|
||||
id?: number | string;
|
||||
|
||||
@@ -117,6 +117,119 @@ describe.each(common.PRIMARY_KEY_TYPES)('/fields', (pkType) => {
|
||||
expect(existingData).toStrictEqual(updatedData);
|
||||
});
|
||||
});
|
||||
|
||||
describe('can create new virtual alias field', () => {
|
||||
it.each(vendors)('%s', async (vendor) => {
|
||||
// Setup
|
||||
const fieldName = 'test_divider';
|
||||
|
||||
// Action
|
||||
const response = await request(getUrl(vendor))
|
||||
.post(`/fields/${localCollectionCountries}`)
|
||||
.send({
|
||||
field: fieldName,
|
||||
type: 'alias',
|
||||
meta: {
|
||||
interface: 'presentation-divider',
|
||||
special: ['alias', 'no-data'],
|
||||
options: { title: 'Test Divider' },
|
||||
},
|
||||
collection: localCollectionCountries,
|
||||
})
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
const response2 = await request(getUrl(vendor))
|
||||
.get(`/fields/${localCollectionCountries}/${fieldName}`)
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
// Assert
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response2.statusCode).toEqual(200);
|
||||
expect(response2.body.data).toEqual(
|
||||
expect.objectContaining({
|
||||
field: fieldName,
|
||||
type: 'alias',
|
||||
collection: localCollectionCountries,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PATCH /:collection', () => {
|
||||
describe('can sort virtual alias field', () => {
|
||||
it.each(vendors)('%s', async (vendor) => {
|
||||
// Setup
|
||||
const fieldName = 'test_divider';
|
||||
const updatedSort = 100;
|
||||
|
||||
// Action
|
||||
const response = await request(getUrl(vendor))
|
||||
.patch(`/fields/${localCollectionCountries}`)
|
||||
.send([{ field: 'test_divider', meta: { sort: updatedSort, group: null } }])
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
const response2 = await request(getUrl(vendor))
|
||||
.get(`/fields/${localCollectionCountries}/${fieldName}`)
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
// Assert
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response2.statusCode).toEqual(200);
|
||||
expect(response2.body.data).toEqual(
|
||||
expect.objectContaining({
|
||||
field: fieldName,
|
||||
type: 'alias',
|
||||
meta: expect.objectContaining({
|
||||
sort: updatedSort,
|
||||
}),
|
||||
collection: localCollectionCountries,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PATCH /:collection/:field', () => {
|
||||
describe('can update virtual alias field', () => {
|
||||
it.each(vendors)('%s', async (vendor) => {
|
||||
// Setup
|
||||
const fieldName = 'test_divider';
|
||||
const updatedTitle = 'Updated Divider';
|
||||
|
||||
// Action
|
||||
const response = await request(getUrl(vendor))
|
||||
.patch(`/fields/${localCollectionCountries}/${fieldName}`)
|
||||
.send({
|
||||
collection: localCollectionCountries,
|
||||
field: fieldName,
|
||||
type: 'alias',
|
||||
schema: null,
|
||||
meta: {
|
||||
options: { title: updatedTitle },
|
||||
},
|
||||
})
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
const response2 = await request(getUrl(vendor))
|
||||
.get(`/fields/${localCollectionCountries}/${fieldName}`)
|
||||
.set('Authorization', `Bearer ${common.USER.ADMIN.TOKEN}`);
|
||||
|
||||
// Assert
|
||||
expect(response.statusCode).toEqual(200);
|
||||
expect(response2.statusCode).toEqual(200);
|
||||
expect(response2.body.data).toEqual(
|
||||
expect.objectContaining({
|
||||
field: fieldName,
|
||||
type: 'alias',
|
||||
meta: expect.objectContaining({
|
||||
options: expect.objectContaining({ title: updatedTitle }),
|
||||
}),
|
||||
collection: localCollectionCountries,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user