-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stub for create dependent features (#4769)
- Loading branch information
Showing
9 changed files
with
203 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
|
||
export const createDependentFeatureSchema = { | ||
$id: '#/components/schemas/createDependentFeatureSchema', | ||
type: 'object', | ||
description: 'Feature dependency on a parent feature in write model', | ||
required: ['feature'], | ||
properties: { | ||
feature: { | ||
type: 'string', | ||
description: 'The name of the feature we depend on.', | ||
example: 'parent_feature', | ||
}, | ||
enabled: { | ||
type: 'boolean', | ||
description: | ||
'Whether the parent feature should be enabled. When `false` variants are ignored. `true` by default.', | ||
example: false, | ||
}, | ||
variants: { | ||
type: 'array', | ||
description: | ||
'The list of variants the parent feature should resolve to. Leave empty when you only want to check the `enabled` status.', | ||
items: { | ||
type: 'string', | ||
}, | ||
example: ['variantA', 'variantB'], | ||
}, | ||
}, | ||
components: {}, | ||
} as const; | ||
|
||
export type CreateDependentFeatureSchema = FromSchema< | ||
typeof createDependentFeatureSchema | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
import { createDependentFeatureSchema } from './create-dependent-feature-schema'; | ||
|
||
export const dependentFeatureSchema = { | ||
$id: '#/components/schemas/dependentFeatureSchema', | ||
type: 'object', | ||
description: 'Feature dependency on a parent feature in read model', | ||
required: ['feature'], | ||
additionalProperties: false, | ||
properties: createDependentFeatureSchema.properties, | ||
components: {}, | ||
} as const; | ||
|
||
export type DependentFeatureSchema = FromSchema<typeof dependentFeatureSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/e2e/api/admin/project/features.dependencies.e2e.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { CreateDependentFeatureSchema } from '../../../../../lib/openapi'; | ||
import { | ||
IUnleashTest, | ||
setupAppWithCustomConfig, | ||
} from '../../../helpers/test-helper'; | ||
import dbInit, { ITestDb } from '../../../helpers/database-init'; | ||
import getLogger from '../../../../fixtures/no-logger'; | ||
|
||
let app: IUnleashTest; | ||
let db: ITestDb; | ||
|
||
beforeAll(async () => { | ||
db = await dbInit('feature_dependencies', getLogger); | ||
app = await setupAppWithCustomConfig( | ||
db.stores, | ||
{ | ||
experimental: { | ||
flags: { | ||
strictSchemaValidation: true, | ||
dependentFeatures: true, | ||
}, | ||
}, | ||
}, | ||
db.rawDatabase, | ||
); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.destroy(); | ||
await db.destroy(); | ||
}); | ||
|
||
const addFeatureDependency = async ( | ||
parentFeature: string, | ||
payload: CreateDependentFeatureSchema, | ||
expectedCode = 200, | ||
) => { | ||
return app.request | ||
.post( | ||
`/api/admin/projects/default/features/${parentFeature}/dependencies`, | ||
) | ||
.send(payload) | ||
.expect(expectedCode); | ||
}; | ||
|
||
test('should add feature dependency', async () => { | ||
const parent = uuidv4(); | ||
const child = uuidv4(); | ||
await app.createFeature(parent); | ||
await app.createFeature(child); | ||
|
||
await addFeatureDependency(parent, { | ||
feature: child, | ||
}); | ||
}); |