mailchimp icon indicating copy to clipboard operation
mailchimp copied to clipboard

How do I test it?

Open chungwong opened this issue 7 years ago • 6 comments

Say I have the following setup in config/test.exs

config :mailchimp,
  api_key: "your api-us10"

for every test, it is making a real call to Mailchimp. Is there a way to prevent it from sending real requests to Mailchimp?

chungwong avatar Sep 04 '18 06:09 chungwong

@chungwong you can follow these guidelines http://blog.plataformatec.com.br/2015/10/mocks-and-explicit-contracts/

klacointe avatar Sep 17 '18 14:09 klacointe

@chungwong and anyone coming here in the future. The library now uses exvcr for testing. All the fixtures are included in the repo so testing is as easy as git pull mix test

ericdude4 avatar Mar 10 '20 02:03 ericdude4

@chungwong and anyone coming here in the future. The library now uses exvcr for testing. All the fixtures are included in the repo so testing is as easy as git pull mix test

@ericdude4 but this is only for the internal tests of this package, right? This does not help me, when I use this package in my application and I want to test my integration is working. How would I test this?

niklasmoeller avatar Apr 01 '20 09:04 niklasmoeller

@niklasmoeller Yes, this is for the internal tests of the package.

If you include this package in your application and write tests, it will make live requests to the Mailchimp API. For this reason, I would recommend using exvcr for your testing as well - unless you want the tests to always make live requests to the Mailchimp API 🤷‍♂

ericdude4 avatar Apr 01 '20 12:04 ericdude4

Another option is to replace Httpoison with Tesla and use provided mock facility.

lessless avatar May 10 '21 19:05 lessless

Thanks @ericdude4. I will take a look into exvcr. This could be a good solution for this and other cases, too.

niklasmoeller avatar May 25 '21 06:05 niklasmoeller