Skip to content

Commit

Permalink
Merge pull request #2 from haqq-network/feat/add-typescript
Browse files Browse the repository at this point in the history
feat: add typescript, yarn, prettier
  • Loading branch information
olegshilov authored Apr 30, 2024
2 parents 6bb0a2b + 9a107e0 commit bb7542c
Show file tree
Hide file tree
Showing 52 changed files with 5,944 additions and 3,957 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
.old_tests/
.parcel-cache/
node_modules/
18 changes: 0 additions & 18 deletions .eslintrc

This file was deleted.

1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

12 changes: 7 additions & 5 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<!--
<!--
1. Before filing a bug please make sure to search the open issues
to make sure it hasn't already been reported: https://github.com/facundoolano/app-store-scraper/issues
2. Also make sure you are running the latest version of the code. Old versions of the package tend to break
due to changes in source pages being scraped.
-->

* Operating System:
* Node version:
* app-play-scraper version:
- Operating System:
- Node version:
- app-play-scraper version:

### Description:

### Description:
Describe your issue here

### Example code:

```js
// Put code to reproduce the issue here
```
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ jobs:
matrix:
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run lint
cache: yarn
- name: Setup dependencies
run: yarn install --immutable
# - name: Run lint
# run: yarn lint
- name: Run build
run: yarn build
- name: Run tests
run: yarn test
65 changes: 44 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
# Logs
logs
*.log
# See http://help.github.com/ignore-files/ for more about ignoring files.

# Runtime data
pids
*.pid
*.seed
*.sw?
# compiled output
/dist
/tmp
/out-tsc

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# dependencies
node_modules

# Coverage directory used by tools like istanbul
coverage
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# node-waf configuration
.lock-wscript
# misc
.lock
.log
/typings

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# System Files
.DS_Store
Thumbs.db

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

/coverage
.env
.log

package-lock.json
.vercel

.parcel-cache
10 changes: 6 additions & 4 deletions test/common.js → .old_tests/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
const assert = require('chai').assert;
const validator = require('validator');

function assertValidUrl (url) {
return assert(validator.isURL(url, { allow_protocol_relative_urls: true }),
`${url} is not a valid url`);
function assertValidUrl(url) {
return assert(
validator.isURL(url, { allow_protocol_relative_urls: true }),
`${url} is not a valid url`,
);
}

function assertValidApp (app) {
function assertValidApp(app) {
assert.isString(app.appId);
assert.isString(app.title);
assert.isString(app.description);
Expand Down
177 changes: 177 additions & 0 deletions .old_tests/lib.app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
'use strict';

const assert = require('chai').assert;
const assertValidUrl = require('./common').assertValidUrl;
const store = require('../index');

describe('App method', () => {
it('should fetch valid application data', () => {
return store.app({ id: '553834731' }).then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(
app.url,
'https://apps.apple.com/us/app/candy-crush-saga/id553834731?uo=4',
);
assertValidUrl(app.icon);

assert.isNumber(app.score);
assert(app.score > 0);
assert(app.score <= 5);

assert.isNotOk(app.ratings);
assert.isNotOk(app.histogram);

assert.isNumber(app.reviews);

assert.isString(app.description);
assert.isString(app.updated);
assert.equal(app.primaryGenre, 'Games');
assert.equal(app.primaryGenreId, 6014);
assert.isArray(app.genres);
assert.isAtLeast(app.genres.length, 1);
assert.isArray(app.genreIds);
assert.isAtLeast(app.genreIds.length, 1);

assert.isString(app.version);
if (app.size) {
assert.isString(app.size);
}
assert.isString(app.contentRating);

assert.isString(app.requiredOsVersion);

assert.equal(app.price, '0');
assert(app.free === true);

assert.equal(app.developer, 'King');
if (app.developerWebsite) {
assertValidUrl(app.developerWebsite);
}

assert(app.screenshots.length);
app.screenshots.map(assertValidUrl);

assert.isString(app.releaseNotes);
});
});

describe('with ratings option enabled', () => {
it('should fetch valid application data', () => {
return store.app({ id: '553834731', ratings: true }).then((app) => {
assert.isNumber(app.ratings);
assert.isObject(app.histogram);
assert.isNumber(app.histogram['1']);
assert.isNumber(app.histogram['2']);
assert.isNumber(app.histogram['3']);
assert.isNumber(app.histogram['4']);
assert.isNumber(app.histogram['5']);
});
});

it('should fetch app with bundle id', () => {
return store
.app({ appId: 'com.midasplayer.apps.candycrushsaga', ratings: true })
.then((app) => {
assert.isNumber(app.ratings);
assert.isObject(app.histogram);
assert.isNumber(app.histogram['1']);
assert.isNumber(app.histogram['2']);
assert.isNumber(app.histogram['3']);
assert.isNumber(app.histogram['4']);
assert.isNumber(app.histogram['5']);
});
});
});

it('should fetch app with bundle id', () => {
return store
.app({ appId: 'com.midasplayer.apps.candycrushsaga' })
.then((app) => {
assert.equal(app.id, '553834731');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(
app.url,
'https://apps.apple.com/us/app/candy-crush-saga/id553834731?uo=4',
);
assert.isNotOk(app.ratings);
assert.isNotOk(app.histogram);
});
});

it('should fetch app in spanish', () => {
return store.app({ id: '553834731', country: 'ar' }).then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(
app.url,
'https://apps.apple.com/ar/app/candy-crush-saga/id553834731?uo=4',
);
});
});

it('should fetch app in french', () => {
return store.app({ id: '553834731', country: 'fr' }).then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(
app.url,
'https://apps.apple.com/fr/app/candy-crush-saga/id553834731?uo=4',
);
});
});

it('should reject the promise for an invalid id', (done) => {
store
.app({ id: '123' })
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.message, 'App not found (404)');
done();
})
.catch(done);
});

it('should reject the promise for an invalid appId', (done) => {
store
.app({ appId: '123' })
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.message, 'App not found (404)');
done();
})
.catch(done);
});

it('should memoize the results when memoize enabled', () => {
const memoized = store.memoized();
return memoized.app({ id: '553834731' }).then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
});
});

it('should memoize the results with custom options', () => {
const memoized = store.memoized({ maxAge: 1000, max: 10 });
return memoized.app({ id: '553834731' }).then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
});
});

it('should be able to set requestOptions', (done) => {
store
.app({
id: '553834731',
requestOptions: {
method: 'DELETE',
},
})
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.response.statusCode, 501);
done();
})
.catch(done);
});
});
13 changes: 6 additions & 7 deletions test/lib.developer.js → .old_tests/lib.developer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ const FACEBOOK_ID = '284882218';

describe('Developer method', () => {
it('should fetch a valid application list', () => {
return store.developer({devId: FACEBOOK_ID})
.then((apps) => {
apps.map(assertValidApp);
apps.map((app) => {
assert.equal(app.developerId, FACEBOOK_ID);
assert.equal(app.developer, 'Meta Platforms, Inc.');
});
return store.developer({ devId: FACEBOOK_ID }).then((apps) => {
apps.map(assertValidApp);
apps.map((app) => {
assert.equal(app.developerId, FACEBOOK_ID);
assert.equal(app.developer, 'Meta Platforms, Inc.');
});
});
});
});
Loading

0 comments on commit bb7542c

Please sign in to comment.