|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { buildCliConfig, buildEnvInput } from '../../common/nodeConfig.js'; |
| 3 | + |
| 4 | +describe('Building cli config and env variable cli input', () => { |
| 5 | + it('Successfully creates a single env variable cli input', async () => { |
| 6 | + const configValuesMap = { plexClaimCode: 'claim123' }; |
| 7 | + const configTranslationMap = { |
| 8 | + plexClaimCode: { |
| 9 | + displayName: 'Plex claim code', |
| 10 | + cliConfigPrefix: 'PLEX_CLAIM=', |
| 11 | + uiControl: { |
| 12 | + type: 'text', |
| 13 | + }, |
| 14 | + isEnvVariable: true, |
| 15 | + addNodeFlow: 'required', |
| 16 | + infoDescription: |
| 17 | + 'Sign in at https://www.plex.tv/claim/, get a code, and paste it here', |
| 18 | + defaultValue: '', |
| 19 | + documentation: 'https://www.plex.tv/claim/', |
| 20 | + }, |
| 21 | + }; |
| 22 | + const cliConfig1 = buildCliConfig({ |
| 23 | + configValuesMap, |
| 24 | + configTranslationMap, |
| 25 | + excludeConfigKeys: [], |
| 26 | + isBuildingEnvInput: true, |
| 27 | + }); |
| 28 | + |
| 29 | + expect(cliConfig1).toEqual('-e PLEX_CLAIM=claim123'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('Successfully creates multiple env variable cli input', async () => { |
| 33 | + const configValuesMap = { plexClaimCode: 'claim123', httpPortEnv: '8080' }; |
| 34 | + const configTranslationMap = { |
| 35 | + plexClaimCode: { |
| 36 | + displayName: 'Plex claim code', |
| 37 | + cliConfigPrefix: 'PLEX_CLAIM=', |
| 38 | + uiControl: { |
| 39 | + type: 'text', |
| 40 | + }, |
| 41 | + isEnvVariable: true, |
| 42 | + addNodeFlow: 'required', |
| 43 | + infoDescription: |
| 44 | + 'Sign in at https://www.plex.tv/claim/, get a code, and paste it here', |
| 45 | + defaultValue: '', |
| 46 | + documentation: 'https://www.plex.tv/claim/', |
| 47 | + }, |
| 48 | + httpPortEnv: { |
| 49 | + displayName: 'HTTP PORT', |
| 50 | + cliConfigPrefix: 'HTTP_PORT=', |
| 51 | + uiControl: { |
| 52 | + type: 'text', |
| 53 | + }, |
| 54 | + isEnvVariable: true, |
| 55 | + }, |
| 56 | + }; |
| 57 | + const cliConfig1 = buildCliConfig({ |
| 58 | + configValuesMap, |
| 59 | + configTranslationMap, |
| 60 | + excludeConfigKeys: [], |
| 61 | + isBuildingEnvInput: true, |
| 62 | + }); |
| 63 | + |
| 64 | + expect(cliConfig1).toEqual('-e PLEX_CLAIM=claim123 -e HTTP_PORT=8080'); |
| 65 | + }); |
| 66 | + |
| 67 | + it('Successfully creates a single cli config input', async () => { |
| 68 | + const configValuesMap = { httpPort: '8080' }; |
| 69 | + const configTranslationMap = { |
| 70 | + httpPort: { |
| 71 | + displayName: 'HTTP PORT', |
| 72 | + cliConfigPrefix: '--http-port=', |
| 73 | + uiControl: { |
| 74 | + type: 'text', |
| 75 | + }, |
| 76 | + }, |
| 77 | + }; |
| 78 | + const cliConfig1 = buildCliConfig({ |
| 79 | + configValuesMap, |
| 80 | + configTranslationMap, |
| 81 | + excludeConfigKeys: [], |
| 82 | + }); |
| 83 | + |
| 84 | + expect(cliConfig1).toEqual('--http-port=8080'); |
| 85 | + }); |
| 86 | + |
| 87 | + it('Successfully creates multiple cli config input', async () => { |
| 88 | + const configValuesMap = { |
| 89 | + httpPort: '8080', |
| 90 | + network: 'Mainnet', |
| 91 | + plexClaimCode: 'claimIgnoreMe', |
| 92 | + }; |
| 93 | + const configTranslationMap = { |
| 94 | + httpPort: { |
| 95 | + displayName: 'HTTP PORT', |
| 96 | + cliConfigPrefix: '--http-port=', |
| 97 | + uiControl: { |
| 98 | + type: 'text', |
| 99 | + }, |
| 100 | + }, |
| 101 | + network: { |
| 102 | + displayName: 'Network', |
| 103 | + defaultValue: 'Mainnet', |
| 104 | + hideFromUserAfterStart: true, |
| 105 | + uiControl: { |
| 106 | + type: 'select/single', |
| 107 | + controlTranslations: [ |
| 108 | + { |
| 109 | + value: 'Mainnet', |
| 110 | + config: '--mainnet', |
| 111 | + }, |
| 112 | + { |
| 113 | + value: 'Holesky', |
| 114 | + config: '--holesky', |
| 115 | + }, |
| 116 | + { |
| 117 | + value: 'Sepolia', |
| 118 | + config: '--sepolia', |
| 119 | + }, |
| 120 | + ], |
| 121 | + }, |
| 122 | + }, |
| 123 | + plexClaimCode: { |
| 124 | + displayName: 'Plex claim code', |
| 125 | + cliConfigPrefix: 'PLEX_CLAIM=', |
| 126 | + uiControl: { |
| 127 | + type: 'text', |
| 128 | + }, |
| 129 | + isEnvVariable: true, |
| 130 | + addNodeFlow: 'required', |
| 131 | + infoDescription: |
| 132 | + 'Sign in at https://www.plex.tv/claim/, get a code, and paste it here', |
| 133 | + defaultValue: '', |
| 134 | + documentation: 'https://www.plex.tv/claim/', |
| 135 | + }, |
| 136 | + }; |
| 137 | + const cliConfig1 = buildCliConfig({ |
| 138 | + configValuesMap, |
| 139 | + configTranslationMap, |
| 140 | + excludeConfigKeys: [], |
| 141 | + }); |
| 142 | + |
| 143 | + expect(cliConfig1).toEqual('--http-port=8080 --mainnet'); |
| 144 | + }); |
| 145 | + |
| 146 | + it('Successfully ignores a single cli config input when building env input', async () => { |
| 147 | + const configValuesMap = { httpPort: '8080' }; |
| 148 | + const configTranslationMap = { |
| 149 | + httpPort: { |
| 150 | + displayName: 'HTTP PORT', |
| 151 | + cliConfigPrefix: '--http-port=', |
| 152 | + uiControl: { |
| 153 | + type: 'text', |
| 154 | + }, |
| 155 | + }, |
| 156 | + }; |
| 157 | + const cliConfig1 = buildCliConfig({ |
| 158 | + configValuesMap, |
| 159 | + configTranslationMap, |
| 160 | + excludeConfigKeys: [], |
| 161 | + isBuildingEnvInput: true, |
| 162 | + }); |
| 163 | + |
| 164 | + expect(cliConfig1).toEqual(''); |
| 165 | + }); |
| 166 | + |
| 167 | + it('Successfully ignores a single cli config input and adds 1 env var when building env input', async () => { |
| 168 | + const configValuesMap = { httpPort: '8080', myFavEnvVar: 'muchwow' }; |
| 169 | + const configTranslationMap = { |
| 170 | + httpPort: { |
| 171 | + displayName: 'HTTP PORT', |
| 172 | + cliConfigPrefix: '--http-port=', |
| 173 | + uiControl: { |
| 174 | + type: 'text', |
| 175 | + }, |
| 176 | + }, |
| 177 | + myFavEnvVar: { |
| 178 | + displayName: 'Plex claim code', |
| 179 | + cliConfigPrefix: 'MYFAVENVVAR=', |
| 180 | + uiControl: { |
| 181 | + type: 'text', |
| 182 | + }, |
| 183 | + isEnvVariable: true, |
| 184 | + }, |
| 185 | + }; |
| 186 | + const cliConfig1 = buildCliConfig({ |
| 187 | + configValuesMap, |
| 188 | + configTranslationMap, |
| 189 | + excludeConfigKeys: [], |
| 190 | + isBuildingEnvInput: true, |
| 191 | + }); |
| 192 | + |
| 193 | + expect(cliConfig1).toEqual('-e MYFAVENVVAR=muchwow'); |
| 194 | + }); |
| 195 | + |
| 196 | + it('[buildEnvInput] Successfully builds env input for 2 user supplied env vars', async () => { |
| 197 | + const configValuesMap = { |
| 198 | + envInput: 'ETHPORTPORT=123456789,BASEPORT=987', |
| 199 | + myFavEnvVar: 'muchwow', |
| 200 | + }; |
| 201 | + const cliConfig1 = buildEnvInput(configValuesMap.envInput); |
| 202 | + |
| 203 | + expect(cliConfig1).toEqual('-e ETHPORTPORT=123456789 -e BASEPORT=987'); |
| 204 | + }); |
| 205 | +}); |
0 commit comments