Skip to content

Commit

Permalink
fix: fix multiple test env
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Mar 11, 2024
1 parent 94d5d9d commit 47ec8b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 15 additions & 6 deletions test/spot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import commercelayer from '../lib/cjs'
import commercelayer, { CommerceLayerStatic } from '../lib/cjs'
import { inspect } from 'util'
import getToken from './token'

const ENV = 'topfarmacia'

;(async () => {

const auth = await getToken('integration')
const auth = await getToken('integration', ENV).catch(err => {
console.log(`${err.message}\n`)
process.exit()
})

const accessToken = auth ? auth.accessToken : ''
const organization = process.env.CL_SDK_ORGANIZATION || 'sdk-test-org'

Expand All @@ -16,13 +20,18 @@ const ENV = 'topfarmacia'
})

try {

const order = await cl.orders.retrieve('nlKhmzozJO')
console.log(order)

const orders = await cl.orders.list({ pageSize: 1 })
console.log(orders)

} catch (error: any) {
console.log(inspect(error, false, null, true))
console.log(error.message)
console.log('\n\n --xx ERROR xx--\n')
if (CommerceLayerStatic.isApiError(error)) console.log(error.errors)
else {
console.log(inspect(error, false, null, true))
console.log(error.message)
}
}

})()
9 changes: 5 additions & 4 deletions test/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export type AccessToken = {
// const endpoint = `https://${organization.toLowerCase()}.${domain ? domain : 'commercelayer.io'}`


export default async (type: TokenType): Promise<AccessToken> => {
export default async (type: TokenType, env?: string): Promise<AccessToken> => {

const env = process.env.CL_SDK_ENVIRONMENT || undefined

if (env) dotenv.config({ path: `env/.env.${env}` })
if (env) {
const cfg = dotenv.config({ path: `./test/env/.env.${env}`, override: true })
if (cfg.error) throw cfg.error
}

const organization = process.env.CL_SDK_ORGANIZATION || ''
const domain = process.env.CL_SDK_DOMAIN
Expand Down

0 comments on commit 47ec8b7

Please sign in to comment.