-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(service): Add contextService and dummy tests against real Shopwa…
…re API
- Loading branch information
Showing
3 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
packages/shopware-6-client/__tests__/services/contextService.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ContextService } from "../../src/index"; | ||
|
||
describe("ContextService", () => { | ||
describe("getCurrencies", () => { | ||
it("should return all currencies", async () => { | ||
try { | ||
const result = await ContextService.getCurrencies(); | ||
expect(result.data).toHaveLength(3); | ||
} catch (e) { | ||
console.error("Connection problem", e); | ||
} | ||
}); | ||
}); | ||
|
||
describe("getLanguages", () => { | ||
it("should return all languages", async () => { | ||
try { | ||
const result = await ContextService.getLanguages(); | ||
expect(result.data).toHaveLength(2); | ||
} catch (e) { | ||
console.error("Connection problem", e); | ||
} | ||
}); | ||
}); | ||
|
||
describe("getCountries", () => { | ||
it("should return all countries", async () => { | ||
try { | ||
const result = await ContextService.getLanguages(); | ||
expect(result.data).toHaveLength(2); | ||
} catch (e) { | ||
console.error("Connection problem", e); | ||
} | ||
}); | ||
}); | ||
|
||
describe("getPaymentMethods", () => { | ||
it("should return all payment methods", async () => { | ||
try { | ||
const result = await ContextService.getPaymentMethods(); | ||
expect(result.data).toHaveLength(4); | ||
} catch (e) { | ||
console.error("Connection problem", e); | ||
} | ||
}); | ||
}); | ||
|
||
describe("getShippingMethods", () => { | ||
it("should return all shipping methods", async () => { | ||
try { | ||
const result = await ContextService.getShippingMethods(); | ||
expect(result.data).toHaveLength(2); | ||
} catch (e) { | ||
console.error("Connection problem", e); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Currency } from "../interfaces/models/system/currency/Currency"; | ||
import { apiService } from "../apiService"; | ||
import { config } from "../settings"; | ||
import { | ||
getContextCurrencyEndpoint, | ||
getContextCountryEndpoint, | ||
getContextPaymentMethodEndpoint, | ||
getContextShippingMethodEndpoint, | ||
getContextLanguageEndpoint | ||
} from "../endpoints"; | ||
import { Country } from "../interfaces/models/system/country/Country"; | ||
import { ShippingMethod } from "../interfaces/models/checkout/shipping/ShippingMethod"; | ||
import { PaymentMethod } from "../interfaces/models/checkout/payment/PaymentMethod"; | ||
import { Language } from "../interfaces/models/framework/language/Language"; | ||
import { SearchResult } from "../interfaces/response/SearchResult"; | ||
|
||
const getCurrencies = async function(): Promise<SearchResult<Currency[]>> { | ||
const resp = await apiService.get( | ||
config.endpoint + getContextCurrencyEndpoint() | ||
); | ||
|
||
return resp.data; | ||
}; | ||
|
||
const getLanguages = async function(): Promise<SearchResult<Language[]>> { | ||
const resp = await apiService.get( | ||
config.endpoint + getContextLanguageEndpoint() | ||
); | ||
|
||
return resp.data; | ||
}; | ||
|
||
const getCountries = async function(): Promise<SearchResult<Country[]>> { | ||
const resp = await apiService.get( | ||
config.endpoint + getContextCountryEndpoint() | ||
); | ||
|
||
return resp.data; | ||
}; | ||
|
||
const getPaymentMethods = async function(): Promise< | ||
SearchResult<PaymentMethod[]> | ||
> { | ||
const resp = await apiService.get( | ||
config.endpoint + getContextPaymentMethodEndpoint() | ||
); | ||
|
||
return resp.data; | ||
}; | ||
|
||
const getShippingMethods = async function(): Promise< | ||
SearchResult<ShippingMethod[]> | ||
> { | ||
const resp = await apiService.get( | ||
config.endpoint + getContextShippingMethodEndpoint() | ||
); | ||
|
||
return resp.data; | ||
}; | ||
|
||
interface ContextService { | ||
getCurrencies: () => Promise<SearchResult<Currency[]>>; | ||
getLanguages: () => Promise<SearchResult<Language[]>>; | ||
getCountries: () => Promise<SearchResult<Country[]>>; | ||
getPaymentMethods: () => Promise<SearchResult<PaymentMethod[]>>; | ||
getShippingMethods: () => Promise<SearchResult<ShippingMethod[]>>; | ||
} | ||
|
||
export const ContextService: ContextService = { | ||
getCurrencies, | ||
getLanguages, | ||
getCountries, | ||
getPaymentMethods, | ||
getShippingMethods | ||
}; |