Add tests for listing GitHub marketplace accounts

Signed-off-by: PauloMigAlmeida <paulo.miguel.almeida.rodenas@gmail.com>
This commit is contained in:
PauloMigAlmeida
2019-12-09 19:36:13 +13:00
committed by Liam Newman
parent de78da4fa6
commit 41b698f0a8
10 changed files with 361 additions and 8 deletions

View File

@@ -17,6 +17,8 @@ public class GHMarketplaceAccount {
private long id;
private String login;
private String email;
@JsonProperty("organization_billing_email")
private String organizationBillingEmail;
private GHMarketplaceAccountType type;
@JsonProperty("marketplace_pending_change")
private GHMarketplacePendingChange marketplacePendingChange;
@@ -32,12 +34,12 @@ public class GHMarketplaceAccount {
*/
GHMarketplaceAccount wrapUp(GitHub root) {
this.root = root;
if (this.marketplacePendingChange != null) {
if (this.marketplacePendingChange != null)
this.marketplacePendingChange.wrapUp(this.root);
}
if (this.marketplacePurchase != null) {
if (this.marketplacePurchase != null)
this.marketplacePurchase.wrapUp(this.root);
}
return this;
}
@@ -77,6 +79,15 @@ public class GHMarketplaceAccount {
return email;
}
/**
* Gets organization billing email.
*
* @return the organization billing email
*/
public String getOrganizationBillingEmail() {
return organizationBillingEmail;
}
/**
* Gets type.
*

View File

@@ -15,7 +15,7 @@ public class GHMarketplacePendingChange {
private GitHub root;
private long id;
@JsonProperty("unit_count")
private long unitCount;
private Long unitCount;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
private GHMarketplacePlan plan;
@JsonProperty("effective_date")
@@ -50,7 +50,7 @@ public class GHMarketplacePendingChange {
*
* @return the unit count
*/
public long getUnitCount() {
public Long getUnitCount() {
return unitCount;
}

View File

@@ -23,7 +23,7 @@ public class GHMarketplacePurchase {
@JsonProperty("free_trial_ends_on")
private String freeTrialEndsOn;
@JsonProperty("unit_count")
private long unitCount;
private Long unitCount;
@JsonProperty("updated_at")
private String updatedAt;
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
@@ -85,7 +85,7 @@ public class GHMarketplacePurchase {
*
* @return the unit count
*/
public long getUnitCount() {
public Long getUnitCount() {
return unitCount;
}

View File

@@ -0,0 +1,123 @@
package org.kohsuke.github;
import org.junit.Test;
import java.io.IOException;
import java.util.List;
import static org.kohsuke.github.GHMarketplaceAccountType.*;
/**
* Tests for the GitHub MarketPlace Plan API methods
*
* @author Paulo Miguel Almeida
*/
public class GHMarketplacePlanTest extends AbstractGitHubWireMockTest {
protected GitHubBuilder getGitHubBuilder() {
return super.getGitHubBuilder()
// ensure that only JWT will be used against the tests below
.withPassword(null, null)
.withJwtToken("bogus");
}
@Test
public void listMarketplacePlans() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().asList();
assertEquals(3, plans.size());
plans.forEach(this::testMarketplacePlan);
}
@Test
public void listAccounts() throws IOException {
List<GHMarketplacePlan> plans = gitHub.listMarketplacePlans().asList();
assertEquals(3, plans.size());
List<GHMarketplaceAccount> marketplaceUsers = plans.get(0).listAccounts().retrieve().asList();
assertEquals(2, marketplaceUsers.size());
marketplaceUsers.forEach(this::testMarketplaceAccount);
}
private void testMarketplacePlan(GHMarketplacePlan plan) {
// Non-nullable fields
assertNotNull(plan.getUrl());
assertNotNull(plan.getAccountsUrl());
assertNotNull(plan.getName());
assertNotNull(plan.getDescription());
assertNotNull(plan.getPriceModel());
assertNotNull(plan.getState());
// primitive fields
assertNotEquals(0L, plan.getId());
assertNotEquals(0L, plan.getNumber());
assertTrue(plan.getMonthlyPriceInCents() >= 0);
// list
assertEquals(2, plan.getBullets().size());
}
private void testMarketplaceAccount(GHMarketplaceAccount account) {
// Non-nullable fields
assertNotNull(account.getLogin());
assertNotNull(account.getUrl());
assertNotNull(account.getType());
assertNotNull(account.getMarketplacePurchase());
testMarketplacePurchase(account.getMarketplacePurchase());
// primitive fields
assertNotEquals(0L, account.getId());
/* logical combination tests */
// Rationale: organization_billing_email is only set when account type is ORGANIZATION.
if (account.getType() == ORGANIZATION)
assertNotNull(account.getOrganizationBillingEmail());
else
assertNull(account.getOrganizationBillingEmail());
// Rationale: marketplace_pending_change isn't always set... This is what GitHub says about it:
// "When someone submits a plan change that won't be processed until the end of their billing cycle,
// you will also see the upcoming pending change."
if (account.getMarketplacePendingChange() != null)
testMarketplacePendingChange(account.getMarketplacePendingChange());
}
private void testMarketplacePurchase(GHMarketplacePurchase marketplacePurchase) {
// Non-nullable fields
assertNotNull(marketplacePurchase.getBillingCycle());
assertNotNull(marketplacePurchase.getNextBillingDate());
assertNotNull(marketplacePurchase.getUpdatedAt());
testMarketplacePlan(marketplacePurchase.getPlan());
/* logical combination tests */
// Rationale: if onFreeTrial is true, then we should see free_trial_ends_on property set to something
// different than null
if (marketplacePurchase.isOnFreeTrial())
assertNotNull(marketplacePurchase.getFreeTrialEndsOn());
else
assertNull(marketplacePurchase.getFreeTrialEndsOn());
// Rationale: if price model is PER_UNIT then unit_count can't be null
if (marketplacePurchase.getPlan().getPriceModel() == GHMarketplacePriceModel.PER_UNIT)
assertNotNull(marketplacePurchase.getUnitCount());
else
assertNull(marketplacePurchase.getUnitCount());
}
private void testMarketplacePendingChange(GHMarketplacePendingChange marketplacePendingChange) {
// Non-nullable fields
assertNotNull(marketplacePendingChange.getEffectiveDate());
testMarketplacePlan(marketplacePendingChange.getPlan());
// primitive fields
assertNotEquals(0L, marketplacePendingChange.getId());
/* logical combination tests */
// Rationale: if price model is PER_UNIT then unit_count can't be null
if (marketplacePendingChange.getPlan().getPriceModel() == GHMarketplacePriceModel.PER_UNIT)
assertNotNull(marketplacePendingChange.getUnitCount());
else
assertNull(marketplacePendingChange.getUnitCount());
}
}

View File

@@ -0,0 +1,93 @@
[
{
"url": "https://api.github.com/orgs/github",
"type": "Organization",
"id": 4,
"login": "github",
"email": null,
"organization_billing_email": "billing@github.com",
"marketplace_pending_change": null,
"marketplace_purchase": {
"billing_cycle": "monthly",
"next_billing_date": "2020-01-01T00:00:00.000Z",
"on_free_trial": false,
"free_trial_ends_on": null,
"unit_count": null,
"updated_at": "2019-11-25T00:00:00.000Z",
"plan": {
"url": "https://api.github.com/marketplace_listing/plans/9",
"accounts_url": "https://api.github.com/marketplace_listing/plans/9/accounts",
"id": 9,
"number": 3,
"name": "Pro",
"description": "A professional-grade CI solution",
"monthly_price_in_cents": 1099,
"yearly_price_in_cents": 11870,
"has_free_trial": false,
"price_model": "flat-rate",
"state": "published",
"unit_name": null,
"bullets": [
"This is the first bullet of the Pro plan",
"This is the second bullet of the Pro plan"
]
}
}
},
{
"url": "https://api.github.com/users/test",
"type": "User",
"id": 2,
"login": "test",
"email": "test@example.com",
"marketplace_pending_change": {
"id": 12,
"unit_count": 8,
"plan": {
"url": "https://api.github.com/marketplace_listing/plans/8",
"accounts_url": "https://api.github.com/marketplace_listing/plans/8/accounts",
"id": 8,
"number": 2,
"name": "Hobby",
"description": "A hobby-grade CI solution",
"monthly_price_in_cents": 1099,
"yearly_price_in_cents": 11870,
"has_free_trial": false,
"price_model": "per-unit",
"state": "published",
"unit_name": "seat",
"bullets": [
"This is the first bullet of the Hobby plan",
"This is the second bullet of the Hobby plan"
]
},
"effective_date": "2020-01-01T00:00:00.000Z"
},
"marketplace_purchase": {
"billing_cycle": "monthly",
"next_billing_date": "2020-01-01T00:00:00.000Z",
"on_free_trial": false,
"free_trial_ends_on": null,
"unit_count": 10,
"updated_at": "2019-11-25T00:00:00.000Z",
"plan": {
"url": "https://api.github.com/marketplace_listing/plans/8",
"accounts_url": "https://api.github.com/marketplace_listing/plans/8/accounts",
"id": 8,
"number": 2,
"name": "Hobby",
"description": "A hobby-grade CI solution",
"monthly_price_in_cents": 1099,
"yearly_price_in_cents": 11870,
"has_free_trial": false,
"price_model": "per-unit",
"state": "published",
"unit_name": "seat",
"bullets": [
"This is the first bullet of the Hobby plan",
"This is the second bullet of the Hobby plan"
]
}
}
}
]

View File

@@ -0,0 +1,35 @@
{
"id" : "2998ad4b-3dbd-374e-a591-d85214efc96b",
"request" : {
"url" : "/marketplace_listing/plans/7/accounts",
"method" : "GET"
},
"response" : {
"status" : 200,
"bodyFileName" : "body-marketplace_listing-stubbed-plans-7-accounts-QgHUA.json",
"headers" : {
"Date" : "Sun, 08 Dec 2019 22:26:01 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Transfer-Encoding" : "chunked",
"Server" : "GitHub.com",
"Status" : "200 OK",
"X-RateLimit-Limit" : "5000",
"X-RateLimit-Remaining" : "4988",
"X-RateLimit-Reset" : "1575844220",
"Cache-Control" : "public, max-age=60, s-maxage=60",
"Vary" : [ "Accept", "Accept-Encoding" ],
"ETag" : "W/\"4bc63e063e145dc1d50cf0144b082493\"",
"X-GitHub-Media-Type" : "unknown, github.v3",
"Access-Control-Expose-Headers" : "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
"Access-Control-Allow-Origin" : "*",
"Strict-Transport-Security" : "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options" : "deny",
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "1; mode=block",
"Referrer-Policy" : "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy" : "default-src 'none'",
"X-GitHub-Request-Id" : "E7A0:3ED0:1B5FEA5:1EFC68E:5DED7878"
}
},
"uuid" : "2998ad4b-3dbd-374e-a591-d85214efc96b"
}

View File

@@ -0,0 +1,35 @@
{
"id" : "c35c1485-2184-3f61-b731-17aa79f4e05a",
"request" : {
"url" : "/marketplace_listing/plans",
"method" : "GET"
},
"response" : {
"status" : 200,
"bodyFileName" : "body-marketplace_listing-stubbed-plans-C43G2.json",
"headers" : {
"Date" : "Sun, 08 Dec 2019 22:26:00 GMT",
"Content-Type" : "application/json; charset=utf-8",
"Transfer-Encoding" : "chunked",
"Server" : "GitHub.com",
"Status" : "200 OK",
"X-RateLimit-Limit" : "5000",
"X-RateLimit-Remaining" : "4989",
"X-RateLimit-Reset" : "1575844220",
"Cache-Control" : "public, max-age=60, s-maxage=60",
"Vary" : [ "Accept", "Accept-Encoding" ],
"ETag" : "W/\"0e89a15f784bd1814d5ae4b05de78ab7\"",
"X-GitHub-Media-Type" : "unknown, github.v3",
"Access-Control-Expose-Headers" : "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type",
"Access-Control-Allow-Origin" : "*",
"Strict-Transport-Security" : "max-age=31536000; includeSubdomains; preload",
"X-Frame-Options" : "deny",
"X-Content-Type-Options" : "nosniff",
"X-XSS-Protection" : "1; mode=block",
"Referrer-Policy" : "origin-when-cross-origin, strict-origin-when-cross-origin",
"Content-Security-Policy" : "default-src 'none'",
"X-GitHub-Request-Id" : "E7A0:3ED0:1B5FE9B:1EFC686:5DED7878"
}
},
"uuid" : "c35c1485-2184-3f61-b731-17aa79f4e05a"
}

View File

@@ -0,0 +1,56 @@
[
{
"url": "https://api.github.com/marketplace_listing/plans/7",
"accounts_url": "https://api.github.com/marketplace_listing/plans/7/accounts",
"id": 7,
"number": 1,
"name": "Free",
"description": "A free CI solution",
"monthly_price_in_cents": 0,
"yearly_price_in_cents": 0,
"price_model": "free",
"has_free_trial": false,
"state": "published",
"unit_name": null,
"bullets": [
"This is the first bullet of the free plan",
"This is the second bullet of the free plan"
]
},
{
"url": "https://api.github.com/marketplace_listing/plans/8",
"accounts_url": "https://api.github.com/marketplace_listing/plans/8/accounts",
"id": 8,
"number": 2,
"name": "Hobby",
"description": "A hobby-grade CI solution",
"monthly_price_in_cents": 1099,
"yearly_price_in_cents": 11870,
"has_free_trial": false,
"price_model": "per-unit",
"state": "published",
"unit_name": "seat",
"bullets": [
"This is the first bullet of the Hobby plan",
"This is the second bullet of the Hobby plan"
]
},
{
"url": "https://api.github.com/marketplace_listing/plans/9",
"accounts_url": "https://api.github.com/marketplace_listing/plans/9/accounts",
"id": 9,
"number": 3,
"name": "Pro",
"description": "A professional-grade CI solution",
"monthly_price_in_cents": 1099,
"yearly_price_in_cents": 11870,
"has_free_trial": false,
"price_model": "flat-rate",
"state": "published",
"unit_name": null,
"bullets": [
"This is the first bullet of the Pro plan",
"This is the second bullet of the Pro plan"
]
}
]