mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-12 01:17:04 +02:00
This PR updates the feature type store to allow for lifetime updates, laying the foundation required to make it user-configurable (#4205).
This commit is contained in:
parent
209cf01477
commit
02635a32ef
@ -67,6 +67,22 @@ class FeatureTypeStore implements IFeatureTypeStore {
|
|||||||
const { present } = result.rows[0];
|
const { present } = result.rows[0];
|
||||||
return present;
|
return present;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateLifetime(
|
||||||
|
name: string,
|
||||||
|
newLifetimeDays: number | null,
|
||||||
|
): Promise<IFeatureType | undefined> {
|
||||||
|
const [updatedType] = await this.db(TABLE)
|
||||||
|
.update({ lifetime_days: newLifetimeDays })
|
||||||
|
.where({ name })
|
||||||
|
.returning(['*']);
|
||||||
|
|
||||||
|
if (updatedType) {
|
||||||
|
return this.rowToFeatureType(updatedType);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
export default FeatureTypeStore;
|
export default FeatureTypeStore;
|
||||||
module.exports = FeatureTypeStore;
|
module.exports = FeatureTypeStore;
|
||||||
|
@ -9,4 +9,8 @@ export interface IFeatureType {
|
|||||||
|
|
||||||
export interface IFeatureTypeStore extends Store<IFeatureType, string> {
|
export interface IFeatureTypeStore extends Store<IFeatureType, string> {
|
||||||
getByName(name: string): Promise<IFeatureType>;
|
getByName(name: string): Promise<IFeatureType>;
|
||||||
|
updateLifetime(
|
||||||
|
name: string,
|
||||||
|
newLifetimeDays: number | null,
|
||||||
|
): Promise<IFeatureType | undefined>;
|
||||||
}
|
}
|
||||||
|
@ -39,3 +39,28 @@ test('should be possible to delete by id', async () => {
|
|||||||
const typesAfterDelete = await featureTypeStore.getAll();
|
const typesAfterDelete = await featureTypeStore.getAll();
|
||||||
expect(typesAfterDelete.length).toBe(4);
|
expect(typesAfterDelete.length).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('update lifetimes', () => {
|
||||||
|
test.each([null, 5])('it sets lifetimeDays to %s', async (newLifetime) => {
|
||||||
|
const featureTypes = await featureTypeStore.getAll();
|
||||||
|
|
||||||
|
for (const type of featureTypes) {
|
||||||
|
const updated = await featureTypeStore.updateLifetime(
|
||||||
|
type.name,
|
||||||
|
newLifetime,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(updated?.lifetimeDays).toBe(newLifetime);
|
||||||
|
|
||||||
|
expect(updated).toMatchObject(
|
||||||
|
await featureTypeStore.getByName(type.name),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("It returns undefined if you try to update a feature type that doesn't exist", async () => {
|
||||||
|
expect(
|
||||||
|
await featureTypeStore.updateLifetime('bogus-type', 40),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
14
src/test/fixtures/fake-feature-type-store.ts
vendored
14
src/test/fixtures/fake-feature-type-store.ts
vendored
@ -45,4 +45,18 @@ export default class FakeFeatureTypeStore implements IFeatureTypeStore {
|
|||||||
`Could not find feature type with name: ${name}`,
|
`Could not find feature type with name: ${name}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateLifetime(
|
||||||
|
name: string,
|
||||||
|
newLifetimeDays: number | null,
|
||||||
|
): Promise<IFeatureType | undefined> {
|
||||||
|
const featureType = this.featureTypes.find(
|
||||||
|
({ name: type }) => type === name,
|
||||||
|
);
|
||||||
|
if (!featureType) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
featureType.lifetimeDays = newLifetimeDays;
|
||||||
|
return featureType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user