@@ -7,19 +7,19 @@ describe('Utility Functions', () => {
77 describe ( 'getLibraryVersion()' , ( ) => {
88 it ( 'should return a valid semver version string' , ( ) => {
99 const version = getLibraryVersion ( ) ;
10-
10+
1111 expect ( version ) . toBeDefined ( ) ;
1212 expect ( typeof version ) . toBe ( 'string' ) ;
1313 expect ( version . length ) . toBeGreaterThan ( 0 ) ;
14-
14+
1515 // Check if it matches semver pattern (major.minor.patch)
1616 const semverPattern = / ^ \d + \. \d + \. \d + (?: - [ a - z A - Z 0 - 9 . - ] + ) ? $ / ;
1717 expect ( version ) . toMatch ( semverPattern ) ;
1818 } ) ;
1919
2020 it ( 'should return the version from package.json' , ( ) => {
2121 const version = getLibraryVersion ( ) ;
22-
22+
2323 // The version should match whatever is in package.json
2424 // We don't hardcode the expected version to avoid breaking on version updates
2525 expect ( version ) . toMatch ( / ^ \d + \. \d + \. \d + (?: - [ a - z A - Z 0 - 9 . - ] + ) ? $ / ) ;
@@ -28,47 +28,67 @@ describe('Utility Functions', () => {
2828 } ) ;
2929
3030 describe ( 'getUserAgent()' , ( ) => {
31+ const originalEnv = process . env ;
32+
33+ beforeEach ( ( ) => {
34+ jest . resetModules ( ) ; // Important to clear cached modules
35+ process . env = { ...originalEnv } ;
36+ } ) ;
37+
38+ afterEach ( ( ) => {
39+ process . env = originalEnv ; // Restore original environment
40+ } ) ;
41+
3142 it ( 'should return a properly formatted User-Agent string' , ( ) => {
3243 const userAgent = getUserAgent ( ) ;
33-
44+
3445 expect ( userAgent ) . toBeDefined ( ) ;
3546 expect ( typeof userAgent ) . toBe ( 'string' ) ;
3647 expect ( userAgent . length ) . toBeGreaterThan ( 0 ) ;
3748 } ) ;
3849
3950 it ( 'should follow the expected User-Agent format' , ( ) => {
4051 const userAgent = getUserAgent ( ) ;
41-
52+
4253 // Should match: nutrient-dws-client-typescript/VERSION
4354 const expectedPattern = / ^ n u t r i e n t - d w s - c l i e n t - t y p e s c r i p t \/ \d + \. \d + \. \d + (?: - [ a - z A - Z 0 - 9 . - ] + ) ? $ / ;
4455 expect ( userAgent ) . toMatch ( expectedPattern ) ;
4556 } ) ;
4657
58+ it ( 'should follow the expected User-Agent format when in development' , ( ) => {
59+ process . env = { ...originalEnv , NODE_ENV : 'development' } ;
60+ const userAgent = getUserAgent ( ) ;
61+
62+ // Should match: nutrient-dws-client-typescript/VERSION-dev
63+ const expectedPattern = / ^ n u t r i e n t - d w s - c l i e n t - t y p e s c r i p t \/ 0 \. 0 \. 0 - d e v $ / ;
64+ expect ( userAgent ) . toMatch ( expectedPattern ) ;
65+ } ) ;
66+
4767 it ( 'should include the correct library name' , ( ) => {
4868 const userAgent = getUserAgent ( ) ;
49-
69+
5070 expect ( userAgent ) . toContain ( 'nutrient-dws-client-typescript' ) ;
5171 } ) ;
5272
5373 it ( 'should include the current library version' , ( ) => {
5474 const userAgent = getUserAgent ( ) ;
5575 const version = getLibraryVersion ( ) ;
56-
76+
5777 expect ( userAgent ) . toContain ( version ) ;
5878 } ) ;
5979
6080 it ( 'should have consistent format across multiple calls' , ( ) => {
6181 const userAgent1 = getUserAgent ( ) ;
6282 const userAgent2 = getUserAgent ( ) ;
63-
83+
6484 expect ( userAgent1 ) . toBe ( userAgent2 ) ;
6585 } ) ;
6686
6787 it ( 'should return the expected User-Agent format with current version' , ( ) => {
6888 const userAgent = getUserAgent ( ) ;
6989 const version = getLibraryVersion ( ) ;
70-
90+
7191 expect ( userAgent ) . toBe ( `nutrient-dws-client-typescript/${ version } ` ) ;
7292 } ) ;
7393 } ) ;
74- } ) ;
94+ } ) ;
0 commit comments