Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Add test for the changes to billing lock function

Matt Robertsc4ecd2e3f11b
diff --git a/app/pkg/dbx/setup.sql b/app/pkg/dbx/setup.sql
index 4f1f7185e..d10a8ed7c 100644
--- a/app/pkg/dbx/setup.sql
+++ b/app/pkg/dbx/setup.sql
@@ -30,3 +30,15 @@ INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type
VALUES ('The Hulk', '[email protected]', 2, now(), 1, 1, 2, '');
INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)
VALUES (5, 2, 'google', 'GO1111', now());
+
+-- Create a tenant that has reached the end of it's trial period
+INSERT INTO tenants (name, subdomain, created_at, cname, invitation, welcome_message, status, is_private, custom_css, logo_bkey, locale, is_email_auth_allowed)
+VALUES ('Trial Expired', 'trial-expired', now(), 'feedback.trial-expired.com', '', '', 1, false, '', '', 'en', true);
+INSERT INTO tenants_billing (tenant_id, paddle_plan_id, paddle_subscription_id, status, subscription_ends_at, trial_ends_at)
+VALUES (3, 1, 1,1, now(), CURRENT_DATE - INTERVAL '10 days');
+INSERT INTO users (name, email, tenant_id, created_at, role, status, avatar_type, avatar_bkey)
+VALUES ('Trial Expired', '[email protected]', 3, now(), 3, 1, 2, '');
+INSERT INTO user_providers (user_id, tenant_id, provider, provider_uid, created_at)
+VALUES (6, 3, 'facebook', 'FB3333', now());
+
+
diff --git a/app/services/sqlstore/postgres/billing_test.go b/app/services/sqlstore/postgres/billing_test.go
new file mode 100644
index 000000000..a34445b42
--- /dev/null
+++ b/app/services/sqlstore/postgres/billing_test.go
@@ -0,0 +1,24 @@
+package postgres_test
+
+import (
+ "testing"
+
+ "github.com/getfider/fider/app/models/cmd"
+
+ . "github.com/getfider/fider/app/pkg/assert"
+ "github.com/getfider/fider/app/pkg/bus"
+)
+
+func TestLockExpiredTenants_ShouldTriggerForOneTenant(t *testing.T) {
+ ctx := SetupDatabaseTest(t)
+ defer TeardownDatabaseTest()
+
+ // There is a tenant with an expired trial setup in the seed for the test database.
+ q := &cmd.LockExpiredTenants{}
+
+ err := bus.Dispatch(ctx, q)
+ Expect(err).IsNil()
+ Expect(q.NumOfTenantsLocked).Equals(int64(1))
+ Expect(q.TenantsLocked).Equals([]int{3})
+
+}