Skip to content

Commit

Permalink
chore: fixed variations test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalaber committed Sep 6, 2024
1 parent da2ff9e commit 103574f
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 80 deletions.
2 changes: 1 addition & 1 deletion oclif.manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "5.16.2",
"version": "5.17.0",
"commands": {
"authCommand": {
"id": "authCommand",
Expand Down
6 changes: 5 additions & 1 deletion src/api/features.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { AxiosError } from 'axios'
import { v2ApiClient as apiClient, apiClient as apiV1Client } from './apiClient'
import {
v2ApiClient as apiClient,
apiClient as apiV1Client,
axiosClient,
} from './apiClient'
import { CreateFeatureParams, Feature, UpdateFeatureParams } from './schemas'
import 'reflect-metadata'
import { buildHeaders } from './common'
Expand Down
4 changes: 2 additions & 2 deletions src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export const CreateVariableDto = schemas.CreateVariableDto
export type UpdateVariableParams = z.infer<typeof schemas.UpdateVariableDto>
export const UpdateVariableDto = schemas.UpdateVariableDto

export type CreateVariationParams = z.infer<typeof schemas.FeatureVariationDto>
export const CreateVariationDto = schemas.FeatureVariationDto
export type CreateVariationParams = z.infer<typeof schemas.CreateVariationDto>
export const CreateVariationDto = schemas.CreateVariationDto

export type UpdateVariationParams = Partial<CreateVariationParams>

Expand Down
1 change: 1 addition & 0 deletions src/api/variations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import apiClient from './apiClient'
import { CreateVariationParams, Feature, Variation } from './schemas'
import { buildHeaders } from './common'

// TODO: Update these functions to use the new v2 API client once the v2 variations endpoint is implemented
const variationsUrl = '/v1/projects/:project/features/:feature/variations'
export class UpdateVariationParams {
@IsString()
Expand Down
88 changes: 45 additions & 43 deletions src/api/zodClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ const Variation = z.object({
.optional(),
_id: z.string(),
})
const CreateVariationDto = z.object({
key: z
.string()
.max(100)
.regex(/^[a-z0-9-_.]+$/),
name: z.string().max(100),
variables: z.record(z.any()).optional(),
})
const FeatureSettings = z.object({
publicName: z.string().max(100),
publicDescription: z.string().max(1000),
Expand All @@ -442,48 +450,6 @@ const FeatureSDKVisibility = z.object({
client: z.boolean(),
server: z.boolean(),
})
const Feature = z.object({
name: z.string().max(100),
key: z
.string()
.max(100)
.regex(/^[a-z0-9-_.]+$/),
description: z.string().max(1000).optional(),
_id: z.string(),
_project: z.string(),
source: z.enum([
'api',
'dashboard',
'importer',
'github.code_usages',
'github.pr_insights',
'bitbucket.code_usages',
'bitbucket.pr_insights',
'terraform',
'cli',
]),
type: z.enum(['release', 'experiment', 'permission', 'ops']).optional(),
status: z.enum(['active', 'complete', 'archived']).optional(),
configurations: z
.record(
z.string(),
z
.object({ targets: z.array(z.any()), status: z.string() })
.partial(),
)
.optional(),
_createdBy: z.string().optional(),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
variations: z.array(Variation),
controlVariation: z.string(),
variables: z.array(Variable),
tags: z.array(z.string()).optional(),
ldLink: z.string().optional(),
readonly: z.boolean(),
settings: FeatureSettings.partial().optional(),
sdkVisibility: FeatureSDKVisibility.optional(),
})
const PreconditionFailedErrorResponse = z.object({
statusCode: z.number(),
message: z.object({}).partial(),
Expand Down Expand Up @@ -612,6 +578,41 @@ const ResultSummaryDto = z.object({
cached: z.boolean(),
updatedAt: z.string().datetime(),
})
const Feature = z.object({
name: z.string().max(100),
key: z
.string()
.max(100)
.regex(/^[a-z0-9-_.]+$/),
description: z.string().max(1000).optional(),
_id: z.string(),
_project: z.string(),
source: z.enum([
'api',
'dashboard',
'importer',
'github.code_usages',
'github.pr_insights',
'bitbucket.code_usages',
'bitbucket.pr_insights',
'terraform',
'cli',
]),
type: z.enum(['release', 'experiment', 'permission', 'ops']).optional(),
status: z.enum(['active', 'complete', 'archived']).optional(),
configurations: z.array(FeatureConfig.partial()).optional(),
_createdBy: z.string().optional(),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime(),
variations: z.array(Variation),
controlVariation: z.string(),
variables: z.array(Variable),
tags: z.array(z.string()).optional(),
ldLink: z.string().optional(),
readonly: z.boolean(),
settings: FeatureSettings.partial().optional(),
sdkVisibility: FeatureSDKVisibility.optional(),
})
const FeatureDataPoint = z.object({
values: z.object({}).partial(),
date: z.string().datetime(),
Expand Down Expand Up @@ -862,6 +863,7 @@ export const schemas = {
FeatureSDKVisibilityDto,
CreateFeatureDto,
Variation,
CreateVariationDto,
FeatureSettings,
FeatureSDKVisibility,
Feature,
Expand Down Expand Up @@ -2144,7 +2146,7 @@ const endpoints = makeApi([
{
name: 'body',
type: 'Body',
schema: FeatureVariationDto,
schema: CreateVariationDto,
},
{
name: 'project',
Expand Down
24 changes: 1 addition & 23 deletions src/commands/features/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,6 @@ describe('features create', () => {
},
}

const mockEnvironments = [
{
key: 'development',
name: 'Development',
_id: '647f62ae749bbe90fb222070',
},
{
key: 'staging',
name: 'Staging',
_id: '637cfe8195279288bc08cb62',
},
{
key: 'production',
name: 'Production',
_id: '637cfe8195279288bc08cb61',
},
]

const mockFeature = {
name: 'Feature Name',
key: 'feature-key',
Expand All @@ -58,11 +40,7 @@ describe('features create', () => {
variations: [],
variables: [],
tags: [],
configurations: {
development: {},
staging: {},
production: {},
},
configurations: [],
ldLink: 'string',
controlVariation: 'variation_id',
readonly: true,
Expand Down
4 changes: 3 additions & 1 deletion src/commands/variations/__snapshots__/create.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`variations create creates a variation and returns the full feature in headless mode 1`] = `
"{\\"_id\\":\\"63b5eea3e6e91987bae47f3a\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"source\\":\\"dashboard\\",\\"type\\":\\"experiment\\",\\"name\\":\\"First Feature\\",\\"description\\":\\"\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.870Z\\",\\"updatedAt\\":\\"2023-06-16T19:27:14.862Z\\",\\"variations\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f40\\",\\"key\\":\\"yo\\",\\"name\\":\\"Yo\\",\\"variables\\":{\\"new-variable\\":false,\\"first-feature\\":true}},{\\"_id\\":\\"63b5eea3e6e91987bae47f41\\",\\"key\\":\\"variation-a\\",\\"name\\":\\"Variation A\\",\\"variables\\":{}},{\\"_id\\":\\"63b5eea3e6e91987bae47f42\\",\\"key\\":\\"variation-b\\",\\"name\\":\\"Variation B\\",\\"variables\\":{}}],\\"controlVariation\\":\\"control\\",\\"variables\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f3c\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"_feature\\":\\"63b5eea3e6e91987bae47f3a\\",\\"name\\":\\"first-feature\\",\\"key\\":\\"first-feature\\",\\"type\\":\\"Boolean\\",\\"status\\":\\"active\\",\\"defaultValue\\":false,\\"source\\":\\"dashboard\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.877Z\\",\\"updatedAt\\":\\"2023-01-04T21:24:51.877Z\\"}],\\"tags\\":[],\\"readonly\\":false,\\"settings\\":{\\"optInEnabled\\":false,\\"publicName\\":\\"\\",\\"publicDescription\\":\\"\\"},\\"sdkVisibility\\":{\\"client\\":false,\\"mobile\\":false,\\"server\\":true}}
"{\\"_id\\":\\"63b5eea3e6e91987bae47f3a\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"source\\":\\"dashboard\\",\\"type\\":\\"experiment\\",\\"name\\":\\"First Feature\\",\\"description\\":\\"\\",\\"key\\":\\"first-feature\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.870Z\\",\\"updatedAt\\":\\"2023-06-16T19:27:14.862Z\\",\\"variations\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f40\\",\\"key\\":\\"yo\\",\\"name\\":\\"Yo\\",\\"variables\\":{\\"new-variable\\":false,\\"first-feature\\":true}},{\\"_id\\":\\"63b5eea3e6e91987bae47f41\\",\\"key\\":\\"variation-a\\",\\"name\\":\\"Variation A\\",\\"variables\\":{}},{\\"_id\\":\\"63b5eea3e6e91987bae47f42\\",\\"key\\":\\"variation-b\\",\\"name\\":\\"Variation B\\",\\"variables\\":{}}],\\"controlVariation\\":\\"control\\",\\"variables\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f3c\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"_feature\\":\\"63b5eea3e6e91987bae47f3a\\",\\"name\\":\\"first-feature\\",\\"key\\":\\"first-feature\\",\\"type\\":\\"Boolean\\",\\"status\\":\\"active\\",\\"defaultValue\\":false,\\"source\\":\\"dashboard\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.877Z\\",\\"updatedAt\\":\\"2023-01-04T21:24:51.877Z\\"}],\\"tags\\":[],\\"readonly\\":false,\\"settings\\":{\\"optInEnabled\\":false,\\"publicName\\":\\"\\",\\"publicDescription\\":\\"\\"},\\"sdkVisibility\\":{\\"client\\":false,\\"mobile\\":false,\\"server\\":true}}
"
`;

Expand All @@ -13,6 +13,7 @@ exports[`variations create creates a variation and returns the full feature in i
\\"type\\": \\"experiment\\",
\\"name\\": \\"First Feature\\",
\\"description\\": \\"\\",
\\"key\\": \\"first-feature\\",
\\"_createdBy\\": \\"google-oauth2|111559006563333334214\\",
\\"createdAt\\": \\"2023-01-04T21:24:51.870Z\\",
\\"updatedAt\\": \\"2023-06-16T19:27:14.862Z\\",
Expand Down Expand Up @@ -86,6 +87,7 @@ exports[`variations create prompts for missing fields in interactive mode 1`] =
\\"type\\": \\"experiment\\",
\\"name\\": \\"First Feature\\",
\\"description\\": \\"\\",
\\"key\\": \\"first-feature\\",
\\"_createdBy\\": \\"google-oauth2|111559006563333334214\\",
\\"createdAt\\": \\"2023-01-04T21:24:51.870Z\\",
\\"updatedAt\\": \\"2023-06-16T19:27:14.862Z\\",
Expand Down
4 changes: 3 additions & 1 deletion src/commands/variations/__snapshots__/update.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports[`variations update prompts for variables when missing in interactive mod
\\"source\\": \\"dashboard\\",
\\"type\\": \\"experiment\\",
\\"name\\": \\"First Feature\\",
\\"key\\": \\"first-feature\\",
\\"description\\": \\"\\",
\\"_createdBy\\": \\"google-oauth2|111559006563333334214\\",
\\"createdAt\\": \\"2023-01-04T21:24:51.870Z\\",
Expand Down Expand Up @@ -82,7 +83,7 @@ exports[`variations update prompts for variables when missing in interactive mod
`;

exports[`variations update updates a variation and returns the full feature in headless mode 1`] = `
"{\\"_id\\":\\"63b5eea3e6e91987bae47f3a\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"source\\":\\"dashboard\\",\\"type\\":\\"experiment\\",\\"name\\":\\"First Feature\\",\\"description\\":\\"\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.870Z\\",\\"updatedAt\\":\\"2023-06-16T19:27:14.862Z\\",\\"variations\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f40\\",\\"key\\":\\"yo\\",\\"name\\":\\"Yo\\",\\"variables\\":{\\"new-variable\\":false,\\"first-feature\\":true}},{\\"_id\\":\\"63b5eea3e6e91987bae47f41\\",\\"key\\":\\"variation-a\\",\\"name\\":\\"Variation A\\",\\"variables\\":{}},{\\"_id\\":\\"63b5eea3e6e91987bae47f42\\",\\"key\\":\\"variation-b\\",\\"name\\":\\"Variation B\\",\\"variables\\":{}}],\\"controlVariation\\":\\"control\\",\\"variables\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f3c\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"_feature\\":\\"63b5eea3e6e91987bae47f3a\\",\\"name\\":\\"first-feature\\",\\"key\\":\\"first-feature\\",\\"type\\":\\"Boolean\\",\\"status\\":\\"active\\",\\"defaultValue\\":false,\\"source\\":\\"dashboard\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.877Z\\",\\"updatedAt\\":\\"2023-01-04T21:24:51.877Z\\"}],\\"tags\\":[],\\"readonly\\":false,\\"settings\\":{\\"optInEnabled\\":false,\\"publicName\\":\\"\\",\\"publicDescription\\":\\"\\"},\\"sdkVisibility\\":{\\"client\\":false,\\"mobile\\":false,\\"server\\":true}}
"{\\"_id\\":\\"63b5eea3e6e91987bae47f3a\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"source\\":\\"dashboard\\",\\"type\\":\\"experiment\\",\\"name\\":\\"First Feature\\",\\"key\\":\\"first-feature\\",\\"description\\":\\"\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.870Z\\",\\"updatedAt\\":\\"2023-06-16T19:27:14.862Z\\",\\"variations\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f40\\",\\"key\\":\\"yo\\",\\"name\\":\\"Yo\\",\\"variables\\":{\\"new-variable\\":false,\\"first-feature\\":true}},{\\"_id\\":\\"63b5eea3e6e91987bae47f41\\",\\"key\\":\\"variation-a\\",\\"name\\":\\"Variation A\\",\\"variables\\":{}},{\\"_id\\":\\"63b5eea3e6e91987bae47f42\\",\\"key\\":\\"variation-b\\",\\"name\\":\\"Variation B\\",\\"variables\\":{}}],\\"controlVariation\\":\\"control\\",\\"variables\\":[{\\"_id\\":\\"63b5eea3e6e91987bae47f3c\\",\\"_project\\":\\"63b5ee5de6e91987bae47f01\\",\\"_feature\\":\\"63b5eea3e6e91987bae47f3a\\",\\"name\\":\\"first-feature\\",\\"key\\":\\"first-feature\\",\\"type\\":\\"Boolean\\",\\"status\\":\\"active\\",\\"defaultValue\\":false,\\"source\\":\\"dashboard\\",\\"_createdBy\\":\\"google-oauth2|111559006563333334214\\",\\"createdAt\\":\\"2023-01-04T21:24:51.877Z\\",\\"updatedAt\\":\\"2023-01-04T21:24:51.877Z\\"}],\\"tags\\":[],\\"readonly\\":false,\\"settings\\":{\\"optInEnabled\\":false,\\"publicName\\":\\"\\",\\"publicDescription\\":\\"\\"},\\"sdkVisibility\\":{\\"client\\":false,\\"mobile\\":false,\\"server\\":true}}
"
`;

Expand All @@ -107,6 +108,7 @@ exports[`variations update updates a variation and returns the full feature in i
\\"source\\": \\"dashboard\\",
\\"type\\": \\"experiment\\",
\\"name\\": \\"First Feature\\",
\\"key\\": \\"first-feature\\",
\\"description\\": \\"\\",
\\"_createdBy\\": \\"google-oauth2|111559006563333334214\\",
\\"createdAt\\": \\"2023-01-04T21:24:51.870Z\\",
Expand Down
3 changes: 2 additions & 1 deletion src/commands/variations/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('variations create', () => {
type: 'experiment',
name: 'First Feature',
description: '',
key: 'first-feature',
_createdBy: 'google-oauth2|111559006563333334214',
createdAt: '2023-01-04T21:24:51.870Z',
updatedAt: '2023-06-16T19:27:14.862Z',
Expand Down Expand Up @@ -189,7 +190,7 @@ describe('variations create', () => {
)
.nock(BASE_URL, (api) =>
api
.get(`/v1/projects/${projectKey}/features/${featureKey}`)
.get(`/v2/projects/${projectKey}/features/${featureKey}`)
.reply(200, mockFeature),
)
.nock(BASE_URL, (api) =>
Expand Down
7 changes: 4 additions & 3 deletions src/commands/variations/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('variations update', () => {
source: 'dashboard',
type: 'experiment',
name: 'First Feature',
key: 'first-feature',
description: '',
_createdBy: 'google-oauth2|111559006563333334214',
createdAt: '2023-01-04T21:24:51.870Z',
Expand Down Expand Up @@ -137,7 +138,7 @@ describe('variations update', () => {
)
.nock(BASE_URL, (api) =>
api
.get(`/v1/projects/${projectKey}/features/${featureKey}`)
.get(`/v2/projects/${projectKey}/features/${featureKey}`)
.reply(200, mockFeature),
)
.nock(BASE_URL, (api) =>
Expand Down Expand Up @@ -188,7 +189,7 @@ describe('variations update', () => {
)
.nock(BASE_URL, (api) =>
api
.get(`/v1/projects/${projectKey}/features/${featureKey}`)
.get(`/v2/projects/${projectKey}/features/${featureKey}`)
.reply(200, mockFeature),
)
.nock(BASE_URL, (api) =>
Expand Down Expand Up @@ -238,7 +239,7 @@ describe('variations update', () => {
)
.nock(BASE_URL, (api) =>
api
.get(`/v1/projects/${projectKey}/features/${featureKey}`)
.get(`/v2/projects/${projectKey}/features/${featureKey}`)
.reply(200, mockFeature),
)
.nock(BASE_URL, (api) =>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/features/quickCreateFeatureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const getQuickConfigurations =
},
},
],
status: 'active',
status: 'inactive',
},
production: {
targets: [
Expand All @@ -106,7 +106,7 @@ export const getQuickConfigurations =
},
},
],
status: 'active',
status: 'inactive',
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions test-utils/dvcTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const mockFeatures = [
variations: [],
variables: [],
tags: [],
configurations: {},
configurations: [],
sdkVisibility: {
mobile: true,
client: true,
Expand All @@ -59,7 +59,7 @@ export const mockFeatures = [
variations: [],
variables: [],
tags: [],
configurations: {},
configurations: [],
sdkVisibility: {
mobile: true,
client: true,
Expand Down

0 comments on commit 103574f

Please sign in to comment.