Skip to content

Commit

Permalink
Wrote more tests for included. Coverage is back up to normal levels
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsky committed Aug 17, 2020
1 parent 2ef1f41 commit 0ddfcec
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 0 deletions.
13 changes: 13 additions & 0 deletions asc/apps_metadata_categories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListAppCategories(t *testing.T) {
Expand All @@ -23,6 +25,17 @@ func TestGetAppCategory(t *testing.T) {
})
}

func TestGetAppCategoryIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"appCategories"},{"type":"appInfos"}]}`, func(ctx context.Context, client *Client) {
category, _, err := client.Apps.GetAppCategory(ctx, "10", &GetAppCategoryQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, category.Included)

assert.NotNil(t, category.Included[0].AppCategory())
assert.Nil(t, category.Included[1].AppCategory())
})
}

func TestGetParentCategoryForAppCategory(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppCategoryResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Apps.GetParentCategoryForAppCategory(ctx, "10", &GetAppCategoryForAppInfoQuery{})
Expand Down
16 changes: 16 additions & 0 deletions asc/apps_metadata_infos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetAppInfo(t *testing.T) {
Expand All @@ -11,6 +13,20 @@ func TestGetAppInfo(t *testing.T) {
})
}

func TestGetAppInfoIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"appInfoLocalizations"},{"type":"appCategories"}]}`, func(ctx context.Context, client *Client) {
infos, _, err := client.Apps.GetAppInfo(ctx, "10", &GetAppInfoQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, infos.Included)

assert.NotNil(t, infos.Included[0].AppInfoLocalization())
assert.NotNil(t, infos.Included[1].AppCategory())

assert.Nil(t, infos.Included[0].AppCategory())
assert.Nil(t, infos.Included[1].AppInfoLocalization())
})
}

func TestListAppInfosForApp(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppInfosResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Apps.ListAppInfosForApp(ctx, "10", &ListAppInfosForAppQuery{})
Expand Down
16 changes: 16 additions & 0 deletions asc/apps_metadata_version_localizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListLocalizationsForAppStoreVersion(t *testing.T) {
Expand All @@ -17,6 +19,20 @@ func TestGetAppStoreVersionLocalization(t *testing.T) {
})
}

func TestGetAppStoreVersionLocalizationIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"appScreenshotSets"},{"type":"appPreviewSets"}]}`, func(ctx context.Context, client *Client) {
localization, _, err := client.Apps.GetAppStoreVersionLocalization(ctx, "10", &GetAppStoreVersionLocalizationQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, localization.Included)

assert.NotNil(t, localization.Included[0].AppScreenshotSet())
assert.NotNil(t, localization.Included[1].AppPreviewSet())

assert.Nil(t, localization.Included[0].AppPreviewSet())
assert.Nil(t, localization.Included[1].AppScreenshotSet())
})
}

func TestCreateAppStoreVersionLocalization(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppStoreVersionLocalizationResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Apps.CreateAppStoreVersionLocalization(ctx, AppStoreVersionLocalizationCreateRequestAttributes{}, "")
Expand Down
33 changes: 33 additions & 0 deletions asc/apps_metadata_versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListAppStoreVersionsForApp(t *testing.T) {
Expand All @@ -17,6 +19,37 @@ func TestGetAppStoreVersion(t *testing.T) {
})
}

func TestGetAppStoreVersionIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[
{"type":"ageRatingDeclarations"},{"type":"appStoreVersionLocalizations"},
{"type":"builds"},{"type":"appStoreVersionPhasedReleases"},
{"type":"routingAppCoverages"},{"type":"appStoreReviewDetails"},
{"type":"appStoreVersionSubmissions"},{"type":"idfaDeclarations"}
]}`, func(ctx context.Context, client *Client) {
version, _, err := client.Apps.GetAppStoreVersion(ctx, "10", &GetAppStoreVersionQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, version.Included)

assert.NotNil(t, version.Included[0].AgeRatingDeclaration())
assert.NotNil(t, version.Included[1].AppStoreVersionLocalization())
assert.NotNil(t, version.Included[2].Build())
assert.NotNil(t, version.Included[3].AppStoreVersionPhasedRelease())
assert.NotNil(t, version.Included[4].RoutingAppCoverage())
assert.NotNil(t, version.Included[5].AppStoreReviewDetail())
assert.NotNil(t, version.Included[6].AppStoreVersionSubmission())
assert.NotNil(t, version.Included[7].IDFADeclaration())

assert.Nil(t, version.Included[0].AppStoreVersionLocalization())
assert.Nil(t, version.Included[0].Build())
assert.Nil(t, version.Included[0].AppStoreVersionPhasedRelease())
assert.Nil(t, version.Included[0].RoutingAppCoverage())
assert.Nil(t, version.Included[0].AppStoreReviewDetail())
assert.Nil(t, version.Included[0].AppStoreVersionSubmission())
assert.Nil(t, version.Included[0].IDFADeclaration())
assert.Nil(t, version.Included[1].AgeRatingDeclaration())
})
}

func TestCreateAppStoreVersion(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppStoreVersionResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Apps.CreateAppStoreVersion(ctx, AppStoreVersionCreateRequestAttributes{}, "10", String("10"))
Expand Down
47 changes: 47 additions & 0 deletions asc/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListApps(t *testing.T) {
Expand All @@ -17,6 +19,51 @@ func TestGetApp(t *testing.T) {
})
}

func TestGetAppIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[
{"type":"betaGroups"},{"type":"appStoreVersions"},{"type":"preReleaseVersions"},
{"type":"betaAppLocalizations"},{"type":"builds"},{"type":"betaLicenseAgreements"},
{"type":"betaAppReviewDetails"},{"type":"appInfos"},{"type":"endUserLicenseAgreements"},
{"type":"appPreOrders"},{"type":"appPrices"},{"type":"territories"},{"type":"inAppPurchases"},
{"type":"gameCenterEnabledVersions"},{"type":"perfPowerMetrics"}
]}`, func(ctx context.Context, client *Client) {
app, _, err := client.Apps.GetApp(ctx, "10", &GetAppQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, app.Included)

assert.NotNil(t, app.Included[0].BetaGroup())
assert.NotNil(t, app.Included[1].AppStoreVersion())
assert.NotNil(t, app.Included[2].PrereleaseVersion())
assert.NotNil(t, app.Included[3].BetaAppLocalization())
assert.NotNil(t, app.Included[4].Build())
assert.NotNil(t, app.Included[5].BetaLicenseAgreement())
assert.NotNil(t, app.Included[6].BetaAppReviewDetail())
assert.NotNil(t, app.Included[7].AppInfo())
assert.NotNil(t, app.Included[8].EndUserLicenseAgreement())
assert.NotNil(t, app.Included[9].AppPreOrder())
assert.NotNil(t, app.Included[10].AppPrice())
assert.NotNil(t, app.Included[11].Territory())
assert.NotNil(t, app.Included[12].InAppPurchase())
assert.NotNil(t, app.Included[13].GameCenterEnabledVersion())
assert.NotNil(t, app.Included[14].PerfPowerMetric())

assert.Nil(t, app.Included[0].AppStoreVersion())
assert.Nil(t, app.Included[0].PrereleaseVersion())
assert.Nil(t, app.Included[0].BetaAppLocalization())
assert.Nil(t, app.Included[0].Build())
assert.Nil(t, app.Included[0].BetaLicenseAgreement())
assert.Nil(t, app.Included[0].BetaAppReviewDetail())
assert.Nil(t, app.Included[0].AppInfo())
assert.Nil(t, app.Included[0].EndUserLicenseAgreement())
assert.Nil(t, app.Included[0].AppPreOrder())
assert.Nil(t, app.Included[0].AppPrice())
assert.Nil(t, app.Included[0].Territory())
assert.Nil(t, app.Included[0].InAppPurchase())
assert.Nil(t, app.Included[0].GameCenterEnabledVersion())
assert.Nil(t, app.Included[0].PerfPowerMetric())
})
}

func TestUpdateApp(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Apps.UpdateApp(ctx, "10", &AppUpdateRequestAttributes{}, []string{"10"}, []string{"10"})
Expand Down
6 changes: 6 additions & 0 deletions asc/asc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,9 @@ func testEndpointExpectingError(t *testing.T, marshalledGot string, endpoint fun
assert.Error(t, err)
assert.Nil(t, got)
}

func testEndpointCustomBehavior(marshalledGot string, behavior func(ctx context.Context, client *Client)) {
client, server := newServer(marshalledGot, true)
defer server.Close()
behavior(context.Background(), client)
}
38 changes: 38 additions & 0 deletions asc/builds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestListBuilds(t *testing.T) {
Expand All @@ -23,6 +25,42 @@ func TestGetBuild(t *testing.T) {
})
}

func TestGetBuildIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[
{"type":"preReleaseVersions"},{"type":"betaTesters"},{"type":"betaBuildLocalizations"},
{"type":"appEncryptionDeclarations"},{"type":"betaAppReviewSubmissions"},{"type":"apps"},
{"type":"buildBetaDetails"},{"type":"appStoreVersions"},{"type":"buildIcons"},
{"type":"perfPowerMetrics"},{"type":"diagnosticSignatures"}
]}`, func(ctx context.Context, client *Client) {
build, _, err := client.Builds.GetBuild(ctx, "10", &GetBuildQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, build.Included)

assert.NotNil(t, build.Included[0].PrereleaseVersion())
assert.NotNil(t, build.Included[1].BetaTester())
assert.NotNil(t, build.Included[2].BetaBuildLocalization())
assert.NotNil(t, build.Included[3].AppEncryptionDeclaration())
assert.NotNil(t, build.Included[4].BetaAppReviewSubmission())
assert.NotNil(t, build.Included[5].App())
assert.NotNil(t, build.Included[6].BuildBetaDetail())
assert.NotNil(t, build.Included[7].AppStoreVersion())
assert.NotNil(t, build.Included[8].BuildIcon())
assert.NotNil(t, build.Included[9].PerfPowerMetric())
assert.NotNil(t, build.Included[10].DiagnosticSignature())

assert.Nil(t, build.Included[0].BetaTester())
assert.Nil(t, build.Included[0].BetaBuildLocalization())
assert.Nil(t, build.Included[0].AppEncryptionDeclaration())
assert.Nil(t, build.Included[0].BetaAppReviewSubmission())
assert.Nil(t, build.Included[0].App())
assert.Nil(t, build.Included[0].BuildBetaDetail())
assert.Nil(t, build.Included[0].AppStoreVersion())
assert.Nil(t, build.Included[0].BuildIcon())
assert.Nil(t, build.Included[0].PerfPowerMetric())
assert.Nil(t, build.Included[0].DiagnosticSignature())
})
}

func TestGetAppForBuild(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Builds.GetAppForBuild(ctx, "10", &GetAppForBuildQuery{})
Expand Down
18 changes: 18 additions & 0 deletions asc/provisioning_bundle_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreateBundleID(t *testing.T) {
Expand Down Expand Up @@ -35,6 +37,22 @@ func TestGetBundleID(t *testing.T) {
})
}

func TestGetBundleIDIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"profiles"},{"type":"bundleIdCapabilities"},{"type":"apps"}]}`, func(ctx context.Context, client *Client) {
bundleID, _, err := client.Provisioning.GetBundleID(ctx, "10", &GetBundleIDQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, bundleID.Included)

assert.NotNil(t, bundleID.Included[0].Profile())
assert.NotNil(t, bundleID.Included[1].BundleIDCapability())
assert.NotNil(t, bundleID.Included[2].App())

assert.Nil(t, bundleID.Included[0].BundleIDCapability())
assert.Nil(t, bundleID.Included[0].App())
assert.Nil(t, bundleID.Included[1].Profile())
})
}

func TestGetAppForBundleID(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Provisioning.GetAppForBundleID(ctx, "10", &GetAppForBundleIDQuery{})
Expand Down
18 changes: 18 additions & 0 deletions asc/provisioning_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreateProfile(t *testing.T) {
Expand All @@ -29,6 +31,22 @@ func TestGetProfile(t *testing.T) {
})
}

func TestGetProfileIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"bundleIds"},{"type":"certificates"},{"type":"devices"}]}`, func(ctx context.Context, client *Client) {
profile, _, err := client.Provisioning.GetProfile(ctx, "10", &GetProfileQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, profile.Included)

assert.NotNil(t, profile.Included[0].BundleID())
assert.NotNil(t, profile.Included[1].Certificate())
assert.NotNil(t, profile.Included[2].Device())

assert.Nil(t, profile.Included[0].Certificate())
assert.Nil(t, profile.Included[0].Device())
assert.Nil(t, profile.Included[1].BundleID())
})
}

func TestGetBundleIDForProfile(t *testing.T) {
testEndpointWithResponse(t, "{}", &BundleIDResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.Provisioning.GetBundleIDForProfile(ctx, "10", &GetBundleIDForProfileQuery{})
Expand Down
17 changes: 17 additions & 0 deletions asc/testflight_beta_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreateBetaGroup(t *testing.T) {
Expand Down Expand Up @@ -35,6 +37,21 @@ func TestGetBetaGroup(t *testing.T) {
})
}

func TestGetBetaGroupIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"apps"},{"type":"builds"},{"type":"betaTesters"}]}`, func(ctx context.Context, client *Client) {
group, _, err := client.TestFlight.GetBetaGroup(ctx, "10", &GetBetaGroupQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, group.Included)

assert.NotNil(t, group.Included[0].App())
assert.NotNil(t, group.Included[1].Build())
assert.NotNil(t, group.Included[2].BetaTester())

assert.Nil(t, group.Included[0].Build())
assert.Nil(t, group.Included[0].BetaTester())
})
}

func TestGetAppForBetaGroup(t *testing.T) {
testEndpointWithResponse(t, "{}", &AppResponse{}, func(ctx context.Context, client *Client) (interface{}, *Response, error) {
return client.TestFlight.GetAppForBetaGroup(ctx, "10", &GetAppForBetaGroupQuery{})
Expand Down
17 changes: 17 additions & 0 deletions asc/testflight_beta_testers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package asc
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCreateBetaTester(t *testing.T) {
Expand Down Expand Up @@ -37,6 +39,21 @@ func TestGetBetaTester(t *testing.T) {
})
}

func TestGetBetaTesterIncludeds(t *testing.T) {
testEndpointCustomBehavior(`{"included":[{"type":"apps"},{"type":"betaGroups"},{"type":"builds"}]}`, func(ctx context.Context, client *Client) {
tester, _, err := client.TestFlight.GetBetaTester(ctx, "10", &GetBetaTesterQuery{})
assert.NoError(t, err)
assert.NotEmpty(t, tester.Included)

assert.NotNil(t, tester.Included[0].App())
assert.NotNil(t, tester.Included[1].BetaGroup())
assert.NotNil(t, tester.Included[2].Build())

assert.Nil(t, tester.Included[0].BetaGroup())
assert.Nil(t, tester.Included[0].Build())
})
}

func TestAddBetaTesterToBetaGroups(t *testing.T) {
testEndpointWithNoContent(t, func(ctx context.Context, client *Client) (*Response, error) {
return client.TestFlight.AddBetaTesterToBetaGroups(ctx, "10", []string{"10"})
Expand Down
Loading

0 comments on commit 0ddfcec

Please sign in to comment.