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

disable slack webhooks if app is not configured #1153

Merged
merged 4 commits into from
Jan 3, 2024

Conversation

lkostrowski
Copy link
Member

Scope of the PR

Related issues

Checklist

@lkostrowski lkostrowski requested a review from a team January 2, 2024 16:27
Copy link

changeset-bot bot commented Jan 2, 2024

🦋 Changeset detected

Latest commit: 8e6a499

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
saleor-app-slack Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-app-slack ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 3, 2024 10:11am
10 Ignored Deployments
Name Status Preview Comments Updated (UTC)
saleor-app-cms-v2 ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-crm ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-data-importer ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-emails-and-messages ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-invoices ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-klaviyo ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-products-feed ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-search ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-segment ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am
saleor-app-taxes ⬜️ Ignored (Inspect) Visit Preview Jan 3, 2024 10:11am

Comment on lines +82 to +90
constructor(
private ownAppId: string,
private client: Pick<Client, "query" | "mutation">,
options?: {
WebhooksClient: WebhooksActivityClient;
},
) {
this.webhooksClient = options?.WebhooksClient ?? new WebhooksActivityClient(this.client);
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do we construct WebhooksActivityClient in here? Even if you want to use the service with a mocked options.WebhookClient you still need to provide a mock for client, even though it's not used anywhere in the service itself - only for initialization

Copy link
Member Author

Choose a reason for hiding this comment

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

Its dependency injection. If you don't provide options, it will automatically create instance. But for testing, you can create any mocked instance of WebhooksActivityClient.

I agree that this implementation should be improved, so graphql client is not needed. It should be hidden behind injected webhooksClient. But this is implementation copy-pasted from Search app.

I'm happy to fix this, but this should probably happen with extraction of this service to shared package and later implementing to every other app.

This PR is meant to quickly implement performance optimization, I will add ticket for it

Comment on lines 78 to 84
const isValidUrl = (url: string) => {
try {
new URL(url);
} catch (e) {
return false;
}
};
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: I think this could be extracted into a separate utility, since the same snippet is used in apps/slack/src/pages/api/configuration.ts

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@witoszekdev witoszekdev self-requested a review January 3, 2024 10:07
@lkostrowski lkostrowski enabled auto-merge (squash) January 3, 2024 10:09
@lkostrowski lkostrowski merged commit 53167f2 into main Jan 3, 2024
19 checks passed
@lkostrowski lkostrowski deleted the slack-disable-400-webhook branch January 3, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants