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

feat(stripe): added new winglib for stripe #279

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

boyney123
Copy link
Contributor

Here is my first attempt at a winglib 🎆

Core features

  • This wing lib allows developers to quickly create stripe webhooks and subscribe to any stripe event.
  • Creating a Stripe webhook will create a API, Queue and Function cloud resources.
  • README has more information on how to use it.

Questions

  • Would love feedback on the pattern, is this what you expect from a winglib? Does it make sense? Could things be done better?
  • I struggled to test this. I wanted to mock out the Stripe webhook verification code (extern), I'm passing environment variable to my /webhook endpoint to make it optional, but not sure if this is best or not?
  • I want to change my ENV variable value IGNORE_STRIPE_WEBHOOK_VALIDATION in my wing test, is this possible? I want a test to set it to false so I can test my edge cases..?
  • @Chriscbr helped me understand why my ENV variables in my extern (inflight) were not present, I expected my preflight ENV variables to be accessible here.... he mentioned @eladb you spoke about this before? Shall we raise an issue for this? Or is this something that doesnt make sense? I'm still wrapping my head around some of this so more than likely just me being a newb here too!
  • I wanted an .env.test file to set my IGNORE_STRIPE_WEBHOOK_VALIDATION to true. This file did not get pick up by my tests when running wing test, is this a bug? From what I read in the docs this is expected? Unless I misread!

Would love some thoughts/advice, I created this to gain more understanding of wing, whilst also hopefully providing value to others with a new lib :)

@boyney123 boyney123 marked this pull request as draft July 3, 2024 15:58
Copy link

wing-cloud-platform bot commented Jul 3, 2024

AppStatusConsoleEndpointsUpdated (UTC)
eladb/winglibs❌ Failed (Inspect)24-6-2024 11:0 (UTC)

@Chriscbr
Copy link
Contributor

Chriscbr commented Jul 3, 2024

I want to change my ENV variable value IGNORE_STRIPE_WEBHOOK_VALIDATION in my wing test, is this possible? I want a test to set it to false so I can test my edge cases..?

IIRC we have an API that lets you check if you're running in a wing test or not -- so you might be able to add some logic to set an environment variable differently by adding a conditional:

bring cloud;

let isTest = nodeof(this).app.isTestEnvironment; // bool

new cloud.Function(inflight () => {
  log(isTest); // "true" if this function is invoked in a wing test, "false" otherwise
});

Something about this API feels clunky though, @eladb wondering if you have ideas for renaming or a better place to put this?

stripe/README.md Outdated Show resolved Hide resolved
Comment on lines +7 to +10
/// The secret key for Stripe as a string
secretKey: str?;
/// Secret key for Stripe as a Secret resource (recommended)
secretKeySecret: cloud.Secret?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked at the OpenAPI example, I did mainly for testing to be honest. Being able to create a Stripe client without secrets defined just passing a string in, seems odd though.

I need to explore how tests mock the Secret resource....and understand this more.

@eladb
Copy link
Contributor

eladb commented Jul 4, 2024

Clunky is the understatement of the year...

Maybe we can sugar nodeof(this).app as @app?

Co-authored-by: Elad Ben-Israel <[email protected]>
@boyney123
Copy link
Contributor Author

I want to change my ENV variable value IGNORE_STRIPE_WEBHOOK_VALIDATION in my wing test, is this possible? I want a test to set it to false so I can test my edge cases..?

IIRC we have an API that lets you check if you're running in a wing test or not -- so you might be able to add some logic to set an environment variable differently by adding a conditional:

bring cloud;

let isTest = nodeof(this).app.isTestEnvironment; // bool

new cloud.Function(inflight () => {
  log(isTest); // "true" if this function is invoked in a wing test, "false" otherwise
});

Something about this API feels clunky though, @eladb wondering if you have ideas for renaming or a better place to put this?

Thanks will have a look.

FWIW it does initially feel odd to me to change implementation code to add test cases in there, rather than somehow mock this stuff in the test itself? Does that make sense? Not sure if it's cos I'm coming from a TS/JS background this is what I expect, or if this is normally fine and to be expected?

Do we expect our users to change libs/implementation code with test edge cases?

@Chriscbr
Copy link
Contributor

Chriscbr commented Jul 8, 2024

Clunky is the understatement of the year...

Maybe we can sugar nodeof(this).app as @app?

I like it!

FWIW it does initially feel odd to me to change implementation code to add test cases in there, rather than somehow mock this stuff in the test itself? Does that make sense? Not sure if it's cos I'm coming from a TS/JS background this is what I expect, or if this is normally fine and to be expected?

Do we expect our users to change libs/implementation code with test edge cases?

Mmm - I think I get what you mean, coupling the logic closer to the test definitions sounds like it might be a better place.

I think the behavior you were expecting (where .env.test variables are automatically loaded) probably should be supported. Smells like a bug - could you open an issue for it?

Perhaps we can try going forward with the changes proposed in winglang/wing#4601, so all environment variables are retrieved during preflight. Then if you want to customize the value of "IGNORE_STRIPE_WEBHOOK_VALIDATION", I think you should be customize it through either the .env.test file or by setting it explicitly:

bring cloud;
bring util;

// mylib.w

class Foo {
  f: cloud.Function;
  new() {
    let key = util.tryEnv("IGNORE_VALIDATION");
    this.f = new cloud.Function(inflight () => {
      log(key ?? "nil");
    });
  }
  pub inflight run() {
    this.f.invoke();
  }
}

// test.w

util.setEnv("IGNORE_VALIDATION", "true");
let f = new Foo();

test "my test" {
  f.run(); // logs "true"
}

Copy link

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Aug 26, 2024
@boyney123 boyney123 removed the Stale label Aug 27, 2024
Copy link

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Sep 17, 2024
@Chriscbr Chriscbr removed the Stale label Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants