public async Task EnsureWorkspaceIsOnPlan(IUser user, long workspaceId, PricingPlans plan) { if (planOfDefaultWorkspaceById.TryGetValue(workspaceId, out var lastPlan) && lastPlan == plan) { return; } planOfDefaultWorkspaceById[workspaceId] = plan; await WorkspaceHelper.SetSubscription(user, workspaceId, plan); }
public async Task EnsureDefaultWorkspaceIsOnPlan(ITogglApi api, PricingPlans plan) { if (planOfDefaultWorkspaceByApi.TryGetValue(api, out var lastPlan) && lastPlan == plan) { return; } planOfDefaultWorkspaceByApi[api] = plan; if (!userByApi.TryGetValue(api, out var user)) { user = await api.User.Get(); userByApi[api] = user; } await EnsureDefaultWorkspaceIsOnPlan(user, plan); }
public static async Task SetSubscription(IUser user, long workspaceId, PricingPlans plan) { var json = $"{{\"pricing_plan_id\":{(int)plan}}}"; await makeRequest($"https://toggl.space/api/v9/workspaces/{workspaceId}/subscription", HttpMethod.Post, user, json); }
public async void CreatingTaskWorksForAllPricingPlansOtherThanTheFreePlan(PricingPlans plan) { var(togglApi, user) = await SetupTestUser(); await plans.EnsureDefaultWorkspaceIsOnPlan(user, plan); var project = createProject(togglApi, user.DefaultWorkspaceId).Wait(); Action creatingTask = () => createTask(togglApi, project, user.Id).Wait(); creatingTask.ShouldNotThrow(); }
private static Dictionary <string, Pricing> GetPricingDictionary(PricingPlans pricing) { return(pricing.Plans.ToDictionary(plan => plan.Id)); }
public Task EnsureDefaultWorkspaceIsOnPlan(IUser user, PricingPlans plan) => EnsureWorkspaceIsOnPlan(user, user.DefaultWorkspaceId.Value, plan);
private static Dictionary <string, Pricing> GetPricingDictionary(PricingPlans pricing) { return(pricing.Plans.Where(plan => PlanIncludesVpn(plan) && IsPlanPrimary(plan)).ToDictionary(plan => plan.Id)); }