Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding botium.json config inside botium.spec.js file #115

Open
piotrjak opened this issue Sep 13, 2019 · 1 comment
Open

Overriding botium.json config inside botium.spec.js file #115

piotrjak opened this issue Sep 13, 2019 · 1 comment
Assignees
Labels

Comments

@piotrjak
Copy link

Hi!
First let me tell you that I've searched through FAQ and both closed and open github issues here and I haven't found an answer to my question.

Case: I have an authentication token that expires after a specific amount of time so I'd like to set this token inside botium.spec.json file, before any of the convos tests run.

Question 1
In https://botium.atlassian.net/wiki/spaces/BOTIUM/pages/360603/Botium+Configuration+-+Capabilities -> Configuration Source -> fourth dot. You write that it's possible to overwrite a specific CAPABILITY config setting with env variable e.g. if I want to override PROJECT_NAME then I set env variable BOTIUM_PROJECT_NAME="My ProjectName". But what about SIMPLEREST_HEADERS_TEMPLATE CAPABILITY which is a JSON object? How can I change SIMPLEREST_HEADERS_TEMPLATE: { "Authorization": "Bearer MYTOKEN" } with env variable? I can't see any example.

Question 2
As I said - I'd like to fetch a token from a server BEFORE any of the tests run and set it on botium object. How can I do it in botium.spec.js file which contains:

const bb = require('botium-bindings');
bb.helper.jest().setupJestTestSuite();

I found that I can modify the header setting inside custom asserter

  assertConvoBegin({ convo, container, args }) {
    console.log(`MyAsserter assertConvoBegin: ${convo.header.name}`);
    return Promise.resolve();
  }

in container desctructured parameter, but I don't want to bind changing the header to a specific test - I'd like to do it before the test.
Can I use BotDriver to do it? How to import this object into this botium.spec.js file?

Looking forward to the response and thank you for your work in botium-bindings. It looks like writing convos files will improve integration testing with our chatbot.

@codeforequity-at
Copy link
Owner

Question 1
Just convert JSON to string:

process.env.BOTIUM_SIMPLEREST_HEADERS_TEMPLATE = JSON.stringify({ "Authorization": "Bearer MYTOKEN" })

Question 2
Several options available. You can use a request hook:

"SIMPLEREST_REQUEST_HOOK": "requestOptions.headers.Authorization = 'Bearer ' + process.env.MY_TOKEN"

Or you can use Scripting functions in Moustache template:

"SIMPLEREST_HEADERS_TEMPLATE:" { "Authorization": "Bearer {{#fnc.func}}process.env.MY_TOKEN{{/fnc.func}}" }

Both should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants