From 1369c73d04292d004f9a87dc30f5d2e71999a6a7 Mon Sep 17 00:00:00 2001 From: michael webber Date: Sat, 4 May 2024 11:44:39 -0400 Subject: [PATCH] add the schema related requests to the api module and tests --- packages/42matters/api.js | 50 +++++++++++++++++++++++++++- packages/42matters/tests/api.test.js | 36 ++++++++++++++++++-- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/packages/42matters/api.js b/packages/42matters/api.js index 47e8fe3..c7ba499 100644 --- a/packages/42matters/api.js +++ b/packages/42matters/api.js @@ -15,10 +15,19 @@ class Api extends ApiKeyRequester { appleSearch: 'ios/apps/search.json', appleQuery: 'ios/apps/query.json', tencentLookup: 'tencent/android/apps/lookup.json', - amazonLookup: 'amazon/android/apps/lookup.json' + amazonLookup: 'amazon/android/apps/lookup.json', + sdks: 'sdks/search.json' } this.URLs = {} this.generateUrls(); + // v1 schema json + this.v1BaseUrl = 'https://data.42matters.com/api/'; + this.v1Endpoints = { + androidCountries: 'meta/android/apps/app_countries.json', + iosCountries: 'meta/ios/apps/app_countries.json', + androidCategories: 'meta/android/apps/app_categories.json', + iosCategories: 'meta/ios/apps/app_secondary_genres.json', + } } generateUrls() { @@ -71,6 +80,45 @@ class Api extends ApiKeyRequester { return this._get(options); } + async getGoogleCategories() { + const options = { + url: this.v1BaseUrl + this.v1Endpoints.androidCategories + } + return this._get(options); + } + + async getAppleGenres() { + const options = { + url: this.v1BaseUrl + this.v1Endpoints.iosCategories + } + return this._get(options); + } + + async getGoogleCountries() { + const options = { + url: this.v1BaseUrl + this.v1Endpoints.androidCountries + } + return this._get(options); + } + + async getAppleCountries() { + const options = { + url: this.v1BaseUrl + this.v1Endpoints.iosCountries + } + return this._get(options); + } + + async getSDKs() { + const options = { + url: this.URLs.sdks, + query: { + platform: 'all', + q: '*' + } + } + return this._get(options); + } + async getGoogleAppData(packageName) { const options = { url: this.URLs.googleLookup, diff --git a/packages/42matters/tests/api.test.js b/packages/42matters/tests/api.test.js index 21659dd..1e99dd0 100644 --- a/packages/42matters/tests/api.test.js +++ b/packages/42matters/tests/api.test.js @@ -18,8 +18,40 @@ describe('42matters API Tests', () => { }); }); - describe('API requests', () => { - describe('App Data requests', () => { + describe('Metadata requests', () => { + it('Should retrieve SDKs', async () => { + const {results: sdks} = await api.getSDKs(); + expect(sdks).toBeDefined(); + expect(sdks.length).toBeGreaterThan(0); + }) + + it('Should retrieve Google countries', async () => { + const {countries} = await api.getGoogleCountries(); + expect(countries).toBeDefined(); + expect(countries.length).toBeGreaterThan(0); + }) + + it('Should retrieve Apple countries', async () => { + const {countries} = await api.getAppleCountries(); + expect(countries).toBeDefined(); + expect(countries.length).toBeGreaterThan(0); + }) + + it('Should retrieve Google categories', async () => { + const {categories} = await api.getGoogleCategories(); + expect(categories).toBeDefined(); + expect(categories.length).toBeGreaterThan(0); + }) + + it('Should retrieve Apple categories', async () => { + const {genres} = await api.getAppleGenres(); + expect(genres).toBeDefined(); + expect(genres.length).toBeGreaterThan(0); + }) + }) + + describe('App Data requests', () => { + describe('Basic requests', () => { it('Should retrieve an android app', async () => { const appData = await api.getGoogleAppData('com.facebook.katana'); expect(appData).toBeDefined();