|
76 | 76 | { name: "number4" } |
77 | 77 | ] |
78 | 78 | ) |
| 79 | + |
| 80 | + stored_leaderboard = |
| 81 | + PluginStore |
| 82 | + .get(DiscourseKofi::PLUGIN_NAME, :leaderboard) |
| 83 | + .map { |e| e.symbolize_keys } |
| 84 | + expect(stored_leaderboard).to eq(leaderboard) |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + describe "goal" do |
| 89 | + before(:example) do |
| 90 | + SiteSetting.kofi_goal_amount = 100 |
| 91 | + Fabricate(:kofi_payment, amount: 10) |
| 92 | + Fabricate(:kofi_payment, amount: 10, timestamp: DateTime.now - 2.months) |
| 93 | + Fabricate(:kofi_subscription, amount: 50) |
| 94 | + |
| 95 | + Fabricate(:kofi_payment, amount: 1000, type: "Commission") |
| 96 | + Fabricate(:kofi_payment, amount: 1000, timestamp: DateTime.now - 2.years) |
| 97 | + end |
| 98 | + |
| 99 | + it "does not calculate a goal when target is 0" do |
| 100 | + SiteSetting.kofi_goal_amount = 0 |
| 101 | + goal = described_class.calculate_goal |
| 102 | + expect(goal[:progress]).to eq(0) |
| 103 | + expect(goal[:target]).to be_nil |
| 104 | + end |
| 105 | + |
| 106 | + it "calculates a monthly goal" do |
| 107 | + goal = described_class.calculate_goal |
| 108 | + expect(goal[:progress]).to eq(60) |
| 109 | + expect(goal[:target]).to be_nil |
| 110 | + end |
| 111 | + |
| 112 | + it "calculates a yearly goal" do |
| 113 | + SiteSetting.kofi_goal_period = "yearly" |
| 114 | + goal = described_class.calculate_goal |
| 115 | + expect(goal[:progress]).to eq(70) |
| 116 | + expect(goal[:target]).to be_nil |
| 117 | + end |
| 118 | + |
| 119 | + it "target is returned when enabled" do |
| 120 | + SiteSetting.kofi_goal_show_amount = true |
| 121 | + goal = described_class.calculate_goal |
| 122 | + expect(goal[:progress]).to eq(60) |
| 123 | + expect(goal[:target]).to eq(100) |
| 124 | + |
| 125 | + stored_goal = |
| 126 | + PluginStore.get(DiscourseKofi::PLUGIN_NAME, :goal).symbolize_keys |
| 127 | + expect(stored_goal).to eq(goal) |
| 128 | + end |
| 129 | + |
| 130 | + it "progress can go over 100%" do |
| 131 | + SiteSetting.kofi_goal_amount = 50 |
| 132 | + goal = described_class.calculate_goal |
| 133 | + expect(goal[:progress]).to eq(120) |
79 | 134 | end |
80 | 135 | end |
81 | 136 | end |
0 commit comments