Skip to content

Commit 19ffd1b

Browse files
committed
Use custom pod when applicable in purchase API
1 parent 7ffd4bf commit 19ffd1b

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

pkg/appstore/appstore_purchase.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ func (t *appstore) purchaseWithParams(acc Account, app App, guid string, pricing
9696
}
9797

9898
func (t *appstore) purchaseRequest(acc Account, app App, storeFront, guid string, pricingParameters string) http.Request {
99+
podPrefix := ""
100+
if acc.Pod != "" {
101+
podPrefix = "p" + acc.Pod + "-"
102+
}
103+
99104
return http.Request{
100-
URL: fmt.Sprintf("https://%s%s", PrivateAppStoreAPIDomain, PrivateAppStoreAPIPathPurchase),
105+
URL: fmt.Sprintf("https://%s%s%s", podPrefix, PrivateAppStoreAPIDomain, PrivateAppStoreAPIPathPurchase),
101106
Method: http.MethodPOST,
102107
ResponseFormat: http.ResponseFormatXML,
103108
Headers: map[string]string{

pkg/appstore/appstore_purchase_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,40 @@ var _ = Describe("AppStore (Purchase)", func() {
9393
})
9494
})
9595

96+
When("request uses a custom pod", func() {
97+
const (
98+
testPod = "42"
99+
testGUID = "001122334455"
100+
)
101+
102+
BeforeEach(func() {
103+
mockMachine.EXPECT().
104+
MacAddress().
105+
Return("00:11:22:33:44:55", nil)
106+
107+
mockPurchaseClient.EXPECT().
108+
Send(gomock.Any()).
109+
Do(func(req http.Request) {
110+
expectedURL := "https://p" + testPod + "-" + PrivateAppStoreAPIDomain + PrivateAppStoreAPIPathPurchase
111+
Expect(req.URL).To(Equal(expectedURL))
112+
Expect(req.Payload).To(BeAssignableToTypeOf(&http.XMLPayload{}))
113+
payload := req.Payload.(*http.XMLPayload)
114+
Expect(payload.Content["guid"]).To(Equal(testGUID))
115+
}).
116+
Return(http.Result[purchaseResult]{}, errors.New(""))
117+
})
118+
119+
It("sends the request to the pod-specific host", func() {
120+
err := as.Purchase(PurchaseInput{
121+
Account: Account{
122+
StoreFront: "143441",
123+
Pod: testPod,
124+
},
125+
})
126+
Expect(err).To(HaveOccurred())
127+
})
128+
})
129+
96130
When("password token is expired", func() {
97131
BeforeEach(func() {
98132
mockMachine.EXPECT().

0 commit comments

Comments
 (0)