@@ -27,12 +27,13 @@ describe('Feature Flag Client', () => {
2727
2828 it ( 'should list feature flags' , async ( ) => {
2929 const appConfigEndpoint = 'https://example.com'
30+ const label = 'test-label'
3031 const getMock = jest . spyOn ( axios , 'get' ) . mockResolvedValue ( {
3132 status : 200 ,
3233 data : featureListResponse
3334 } )
3435
35- const results = await listFeatureFlags ( appConfigEndpoint )
36+ const results = await listFeatureFlags ( appConfigEndpoint , label )
3637 expect ( results . items . length ) . toEqual ( 1 )
3738 expect ( results . items [ 0 ] . key ) . toEqual (
3839 '.appconfig.featureflag/featureFlagId1'
@@ -41,27 +42,70 @@ describe('Feature Flag Client', () => {
4142
4243 it ( 'should throw error when list api fails' , async ( ) => {
4344 const appConfigEndpoint = 'https://example.com'
45+ const label = 'test-label'
4446
4547 const getMock = jest . spyOn ( axios , 'get' ) . mockResolvedValue ( {
4648 status : 500 ,
4749 statusText : 'Internal Server Error'
4850 } )
4951
50- await expect ( listFeatureFlags ( appConfigEndpoint ) ) . rejects . toThrow ( ApiError )
52+ await expect ( listFeatureFlags ( appConfigEndpoint , label ) ) . rejects . toThrow (
53+ ApiError
54+ )
5155 } )
5256
53- it ( 'create or update feature flag' , async ( ) => {
57+ it ( 'can create or update feature flag' , async ( ) => {
5458 const appConfigEndpoint = 'https://example.com'
5559 const featureFlagId = 'featureFlagId1'
60+ const label = ''
5661 const value = getDummyFeatureFlagItem ( featureFlagId )
5762
5863 const getMock = jest . spyOn ( axios , 'put' ) . mockResolvedValue ( {
5964 status : 200
6065 } )
6166
62- await createOrUpdateFeatureFlag ( appConfigEndpoint , featureFlagId , value )
67+ await createOrUpdateFeatureFlag (
68+ appConfigEndpoint ,
69+ featureFlagId ,
70+ value ,
71+ label
72+ )
73+ expect ( getMock ) . toBeCalledWith (
74+ `${ appConfigEndpoint } /kv/.appconfig.featureflag%2FfeatureFlagId1?api-version=2023-11-01&label=` ,
75+ {
76+ content_type :
77+ 'application/vnd.microsoft.appconfig.ff+json;charset=utf-8' ,
78+ value : JSON . stringify ( value )
79+ } ,
80+ {
81+ headers : {
82+ Accept : '*/*' ,
83+ Authorization : 'Bearer token' ,
84+ 'Content-Type' : 'application/vnd.microsoft.appconfig.kv+json'
85+ }
86+ }
87+ )
88+ } )
89+
90+ it ( 'can create or update feature flag with label' , async ( ) => {
91+ const appConfigEndpoint = 'https://example.com'
92+ const featureFlagId = 'featureFlagId1'
93+ // Use a label with special characters to test URL encoding
94+ const label = 'test label/with special&chars'
95+ const value = getDummyFeatureFlagItem ( featureFlagId )
96+
97+ const getMock = jest . spyOn ( axios , 'put' ) . mockResolvedValue ( {
98+ status : 200
99+ } )
100+
101+ await createOrUpdateFeatureFlag (
102+ appConfigEndpoint ,
103+ featureFlagId ,
104+ value ,
105+ label
106+ )
63107 expect ( getMock ) . toBeCalledWith (
64- `${ appConfigEndpoint } /kv/.appconfig.featureflag%2FfeatureFlagId1?api-version=2023-11-01` ,
108+ `${ appConfigEndpoint } /kv/.appconfig.featureflag%2FfeatureFlagId1?api-version=2023-11-01&label=test%20label%2Fwith%20special%26chars ` ,
65109 {
66110 content_type :
67111 'application/vnd.microsoft.appconfig.ff+json;charset=utf-8' ,
@@ -80,6 +124,7 @@ describe('Feature Flag Client', () => {
80124 it ( 'should throw error when create or update feature flag fails' , async ( ) => {
81125 const appConfigEndpoint = 'https://example.com'
82126 const featureFlagId = 'featureFlagId1'
127+ const label = 'test-label'
83128 const value = getDummyFeatureFlagItem ( featureFlagId )
84129
85130 const getMock = jest . spyOn ( axios , 'put' ) . mockResolvedValue ( {
@@ -88,21 +133,22 @@ describe('Feature Flag Client', () => {
88133 } )
89134
90135 await expect (
91- createOrUpdateFeatureFlag ( appConfigEndpoint , featureFlagId , value )
136+ createOrUpdateFeatureFlag ( appConfigEndpoint , featureFlagId , value , label )
92137 ) . rejects . toThrow ( ApiError )
93138 } )
94139
95140 it ( 'should delete feature flag' , async ( ) => {
96141 const appConfigEndpoint = 'https://example.com'
97142 const featureFlagId = 'featureFlagId1'
143+ const label = 'test label/with special&chars'
98144
99145 const getMock = jest . spyOn ( axios , 'delete' ) . mockResolvedValue ( {
100146 status : 200
101147 } )
102148
103- await deleteFeatureFlag ( appConfigEndpoint , featureFlagId )
149+ await deleteFeatureFlag ( appConfigEndpoint , featureFlagId , label )
104150 expect ( getMock ) . toBeCalledWith (
105- `${ appConfigEndpoint } /kv/.appconfig.featureflag%2FfeatureFlagId1?api-version=2023-11-01` ,
151+ `${ appConfigEndpoint } /kv/.appconfig.featureflag%2FfeatureFlagId1?api-version=2023-11-01&label=test%20label%2Fwith%20special%26chars ` ,
106152 {
107153 headers : {
108154 Accept : '*/*' ,
@@ -116,13 +162,14 @@ describe('Feature Flag Client', () => {
116162 it ( 'should throw error when delete feature flag fails' , async ( ) => {
117163 const appConfigEndpoint = 'https://example.com'
118164 const featureFlagId = 'featureFlagId1'
165+ const label = 'test-label'
119166
120167 const getMock = jest . spyOn ( axios , 'delete' ) . mockResolvedValue ( {
121168 status : 500
122169 } )
123170
124171 await expect (
125- deleteFeatureFlag ( appConfigEndpoint , featureFlagId )
172+ deleteFeatureFlag ( appConfigEndpoint , featureFlagId , label )
126173 ) . rejects . toThrow ( ApiError )
127174 } )
128175
0 commit comments