mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
fix: update context field does not await the response (#1027)
This commit is contained in:
parent
bb283b9792
commit
9ad0ed50de
@ -2,6 +2,7 @@ import { Knex } from 'knex';
|
|||||||
import { Logger, LogProvider } from '../logger';
|
import { Logger, LogProvider } from '../logger';
|
||||||
import {
|
import {
|
||||||
IContextField,
|
IContextField,
|
||||||
|
IContextFieldDto,
|
||||||
IContextFieldStore,
|
IContextFieldStore,
|
||||||
} from '../types/stores/context-field-store';
|
} from '../types/stores/context-field-store';
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ interface ICreateContextField {
|
|||||||
description: string;
|
description: string;
|
||||||
stickiness: boolean;
|
stickiness: boolean;
|
||||||
sort_order: number;
|
sort_order: number;
|
||||||
legal_values?: string[];
|
legal_values?: string;
|
||||||
updated_at: Date;
|
updated_at: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,15 +44,15 @@ class ContextFieldStore implements IContextFieldStore {
|
|||||||
this.logger = getLogger('context-field-store.ts');
|
this.logger = getLogger('context-field-store.ts');
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
fieldToRow(
|
||||||
fieldToRow(data): ICreateContextField {
|
data: IContextFieldDto,
|
||||||
|
): Omit<ICreateContextField, 'updated_at'> {
|
||||||
return {
|
return {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
stickiness: data.stickiness,
|
stickiness: data.stickiness,
|
||||||
sort_order: data.sortOrder, // eslint-disable-line
|
sort_order: data.sortOrder, // eslint-disable-line
|
||||||
legal_values: data.legalValues ? data.legalValues.join(',') : null, // eslint-disable-line
|
legal_values: data.legalValues ? data.legalValues.join(',') : undefined, // eslint-disable-line
|
||||||
updated_at: data.createdAt, // eslint-disable-line
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,20 +88,19 @@ class ContextFieldStore implements IContextFieldStore {
|
|||||||
return present;
|
return present;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
async create(contextField: IContextFieldDto): Promise<IContextField> {
|
||||||
async create(contextField): Promise<IContextField> {
|
|
||||||
const row = await this.db(TABLE)
|
const row = await this.db(TABLE)
|
||||||
.insert(this.fieldToRow(contextField))
|
.insert(this.fieldToRow(contextField))
|
||||||
.returning('*');
|
.returning('*');
|
||||||
return mapRow(row);
|
return mapRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
async update(data: IContextFieldDto): Promise<IContextField> {
|
||||||
async update(data): Promise<IContextField> {
|
const row = await this.db(TABLE)
|
||||||
const row = this.db(TABLE)
|
|
||||||
.where({ name: data.name })
|
.where({ name: data.name })
|
||||||
.update(this.fieldToRow(data))
|
.update(this.fieldToRow(data))
|
||||||
.returning('*');
|
.returning('*');
|
||||||
|
|
||||||
return mapRow(row);
|
return mapRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,4 +109,3 @@ class ContextFieldStore implements IContextFieldStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export default ContextFieldStore;
|
export default ContextFieldStore;
|
||||||
module.exports = ContextFieldStore;
|
|
||||||
|
@ -153,3 +153,29 @@ test('should validate name to not ok for non url-friendly', async () => {
|
|||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should update context field with stickiness', async () => {
|
||||||
|
const name = 'with-sticky-update';
|
||||||
|
await app.request
|
||||||
|
.post('/api/admin/context')
|
||||||
|
.send({
|
||||||
|
name,
|
||||||
|
description: 'A context field supporting stickiness',
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
await app.request
|
||||||
|
.put(`/api/admin/context/${name}`)
|
||||||
|
.send({
|
||||||
|
description: 'asd',
|
||||||
|
legalValues: [],
|
||||||
|
name,
|
||||||
|
stickiness: true,
|
||||||
|
})
|
||||||
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
const res = await app.request.get(`/api/admin/context/${name}`);
|
||||||
|
const contextField = res.body;
|
||||||
|
|
||||||
|
expect(contextField.description).toBe('asd');
|
||||||
|
expect(contextField.stickiness).toBe(true);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user