|
16 | 16 | import com.moesif.api.models.CampaignModel; |
17 | 17 | import com.moesif.api.models.CampaignBuilder; |
18 | 18 | import static org.mockito.Mockito.when; |
| 19 | +import com.moesif.api.models.SubscriptionBuilder; |
| 20 | +import com.moesif.api.models.SubscriptionModel; |
19 | 21 |
|
20 | 22 |
|
21 | 23 | public class MoesifServletTests extends TestCase { |
@@ -241,5 +243,67 @@ public void testUpdateCompaniesBatch() throws Throwable { |
241 | 243 | filter.updateCompaniesBatch(companies); |
242 | 244 | } |
243 | 245 |
|
| 246 | + public void testUpdateSubscription() throws Throwable { |
| 247 | + |
| 248 | + // Only subscriptionId is required |
| 249 | + // metadata can be any custom object |
| 250 | + SubscriptionModel subscription = new SubscriptionBuilder() |
| 251 | + .subscriptionId("sub_12345") |
| 252 | + .companyId("67890") |
| 253 | + .currentPeriodStart(new Date()) |
| 254 | + .currentPeriodEnd(new Date()) |
| 255 | + .status("active") |
| 256 | + .metadata(APIHelper.deserialize("{" + |
| 257 | + "\"email\": \"[email protected]\"," + |
| 258 | + "\"string_field\": \"value_1\"," + |
| 259 | + "\"number_field\": 0," + |
| 260 | + "\"object_field\": {" + |
| 261 | + "\"field_1\": \"value_1\"," + |
| 262 | + "\"field_2\": \"value_2\"" + |
| 263 | + "}" + |
| 264 | + "}")) |
| 265 | + .build(); |
| 266 | + |
| 267 | + filter.updateSubscription(subscription); |
| 268 | + } |
| 269 | + |
| 270 | + public void testUpdateSubscriptionsBatch() throws Throwable { |
| 271 | + |
| 272 | + List<SubscriptionModel> subscriptions = new ArrayList<SubscriptionModel>(); |
| 273 | + |
| 274 | + HashMap<String, Object> metadata = new HashMap<String, Object>(); |
| 275 | + metadata = APIHelper.deserialize("{" + |
| 276 | + "\"email\": \"[email protected]\"," + |
| 277 | + "\"string_field\": \"value_1\"," + |
| 278 | + "\"number_field\": 0," + |
| 279 | + "\"object_field\": {" + |
| 280 | + "\"field_1\": \"value_1\"," + |
| 281 | + "\"field_2\": \"value_2\"" + |
| 282 | + "}" + |
| 283 | + "}"); |
| 284 | + |
| 285 | + SubscriptionModel subscriptionA = new SubscriptionBuilder() |
| 286 | + .subscriptionId("sub_12345") |
| 287 | + .companyId("67890") |
| 288 | + .currentPeriodStart(new Date()) |
| 289 | + .currentPeriodEnd(new Date()) |
| 290 | + .status("active") |
| 291 | + .metadata(metadata) |
| 292 | + .build(); |
| 293 | + |
| 294 | + SubscriptionModel subscriptionB = new SubscriptionBuilder() |
| 295 | + .subscriptionId("sub_67890") |
| 296 | + .companyId("12345") |
| 297 | + .currentPeriodStart(new Date()) |
| 298 | + .currentPeriodEnd(new Date()) |
| 299 | + .status("active") |
| 300 | + .metadata(metadata) |
| 301 | + .build(); |
| 302 | + |
| 303 | + subscriptions.add(subscriptionA); |
| 304 | + subscriptions.add(subscriptionB); |
| 305 | + |
| 306 | + filter.updateSubscriptionsBatch(subscriptions); |
| 307 | + } |
244 | 308 |
|
245 | 309 | } |
0 commit comments