1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat(#4205): modify feature type store to allow lifetime updates (#4252)

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:
Thomas Heartman 2023-07-17 14:36:43 +02:00 committed by GitHub
parent 209cf01477
commit 02635a32ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 0 deletions

View File

@ -67,6 +67,22 @@ class FeatureTypeStore implements IFeatureTypeStore {
const { present } = result.rows[0];
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;
module.exports = FeatureTypeStore;

View File

@ -9,4 +9,8 @@ export interface IFeatureType {
export interface IFeatureTypeStore extends Store<IFeatureType, string> {
getByName(name: string): Promise<IFeatureType>;
updateLifetime(
name: string,
newLifetimeDays: number | null,
): Promise<IFeatureType | undefined>;
}

View File

@ -39,3 +39,28 @@ test('should be possible to delete by id', async () => {
const typesAfterDelete = await featureTypeStore.getAll();
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();
});
});

View File

@ -45,4 +45,18 @@ export default class FakeFeatureTypeStore implements IFeatureTypeStore {
`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;
}
}