Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adfineberg committed Jun 6, 2024
1 parent 0d5cdc7 commit f8f7364
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/e2e-credentials-store/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = deepMerge(require('../../jest.base.config.js'), {
displayName: 'e2e-credentials-store',
rootDir: `${__dirname}`,
collectCoverageFrom: ['!<rootDir>/index.ts'],
testEnvironment: 'jest-dynalite/dist/environment',
coverageThreshold: {
// Slowly start increasing here, never decrease!
global: {
Expand Down
1 change: 1 addition & 0 deletions packages/persistent-pool/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = deepMerge(require('../../jest.base.config.js'), {
displayName: 'persistent-pool',
rootDir: `${__dirname}`,
collectCoverageFrom: ['!<rootDir>/src/index.ts'],
testEnvironment: './dist/test/lib/dynamodb/environment',
coverageThreshold: {
global: {
branches: 90,
Expand Down
37 changes: 28 additions & 9 deletions packages/salesforce-adapter/e2e_test/jest_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createEnvUtils, creds, CredsLease, CredsSpec, SuspendCredentialsError } from '@salto-io/e2e-credentials-store'
import {
createEnvUtils,
creds,
CredsLease,
CredsSpec,
SuspendCredentialsError,
} from '@salto-io/e2e-credentials-store'
import { logger } from '@salto-io/logging'
import { ApiLimitsTooLowError, validateCredentials } from '../src/client/client'
import { UsernamePasswordCredentials } from '../src/types'
Expand All @@ -25,15 +31,18 @@ const log = logger(module)
const MIN_API_REQUESTS_NEEDED = 2000
const NOT_ENOUGH_API_REQUESTS_SUSPENSION_TIMEOUT = 1000 * 60 * 60

export const credsSpec = (envName?: string): CredsSpec<UsernamePasswordCredentials> => {
const addEnvName = (varName: string): string => (envName === undefined ? varName : [varName, envName].join('_'))
export const credsSpec = (
envName?: string,
): CredsSpec<UsernamePasswordCredentials> => {
const addEnvName = (varName: string): string =>
envName === undefined ? varName : [varName, envName].join('_')
const userEnvVarName = addEnvName('SF_USER')
const passwordEnvVarName = addEnvName('SF_PASSWORD')
const tokenEnvVarName = addEnvName('SF_TOKEN')
const sandboxEnvVarName = addEnvName('SF_SANDBOX')
return {
envHasCreds: env => userEnvVarName in env,
fromEnv: env => {
envHasCreds: (env) => userEnvVarName in env,
fromEnv: (env) => {
const envUtils = createEnvUtils(env)
return {
username: envUtils.required(userEnvVarName),
Expand All @@ -42,12 +51,20 @@ export const credsSpec = (envName?: string): CredsSpec<UsernamePasswordCredentia
isSandbox: envUtils.bool(sandboxEnvVarName),
}
},
validate: async (credentials: UsernamePasswordCredentials): Promise<void> => {
validate: async (
credentials: UsernamePasswordCredentials,
): Promise<void> => {
try {
await validateCredentials(new UsernamePasswordCredentials(credentials), MIN_API_REQUESTS_NEEDED)
await validateCredentials(
new UsernamePasswordCredentials(credentials),
MIN_API_REQUESTS_NEEDED,
)
} catch (e) {
if (e instanceof ApiLimitsTooLowError) {
throw new SuspendCredentialsError(e, NOT_ENOUGH_API_REQUESTS_SUSPENSION_TIMEOUT)
throw new SuspendCredentialsError(
e,
NOT_ENOUGH_API_REQUESTS_SUSPENSION_TIMEOUT,
)
}
throw e
}
Expand All @@ -58,7 +75,9 @@ export const credsSpec = (envName?: string): CredsSpec<UsernamePasswordCredentia
}

export type TestHelpers = {
credentials: (envName?: string) => Promise<CredsLease<UsernamePasswordCredentials>>
credentials: (
envName?: string,
) => Promise<CredsLease<UsernamePasswordCredentials>>
CUSTOM_OBJECT: string
}
export const testHelpers = (): TestHelpers => ({
Expand Down

0 comments on commit f8f7364

Please sign in to comment.