Skip to content

Commit

Permalink
🐛 fix logic post contibs + add more tests (#74)
Browse files Browse the repository at this point in the history
* add logs

* logs gh

* 🐛 fix logic post contribs
  • Loading branch information
a-tokyo committed Mar 28, 2022
1 parent 4094354 commit 364f654
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 40 deletions.
53 changes: 32 additions & 21 deletions .github/workflows/test-publish.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
name: Test Release Publish

on:
push:
branches:
- main
on: [push]

jobs:
test_release_publish:
name: Running tests and releasing to NPM and deploying demo
test:
name: Run tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/checkout@v1
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -31,8 +26,34 @@ jobs:
run: yarn install
- name: Test
run: yarn test --ci --bail
- name: Lint
run: yarn eslint .
- name: Test TypeScript Type Definitions
run: yarn test:typescript
- name: Build
run: NODE_ENV=production yarn build

release_publish:
name: Release to Github and publish to NPM
runs-on: ubuntu-latest
needs: test
if: success() && github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v1
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ubuntu-latest-node-12.x-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
ubuntu-latest-node-12.x-yarn-
- uses: actions/setup-node@v1
with:
node-version: 12.x
registry-url: https://registry.npmjs.org/
- name: Install
run: yarn install
- name: Build
run: NODE_ENV=production yarn build
- name: Setup env vars
Expand All @@ -54,13 +75,3 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: github.event.pull_request.user.login != 'dependabot'
- uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
directory: ./coverage # optional
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./demo/dist
67 changes: 66 additions & 1 deletion src/appleAuthHelpers/appleAuthHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('appleAuthHelpers', () => {

beforeEach(() => {
/** Mock apple funcs */
AppleIDAuthInitFn = jest.fn(() => Promise.resolve(true));
AppleIDAuthInitFn = jest.fn(() => true);
AppleIDAuthSignInFn = jest.fn(() =>
Promise.resolve(AppleIDAuthSignInFnResponse),
);
Expand Down Expand Up @@ -72,6 +72,71 @@ describe('appleAuthHelpers', () => {
expect(input.onError.mock.calls[0][0]).toEqual(expect.any(Error));
});

it('should return undefined and call onError if apple signIn throws', async () => {
window.AppleID = {
auth: {
init: AppleIDAuthInitFn,
signIn: () => Promise.reject(new Error('test error')),
},
};
const input = {
authOptions: _authOptions,
onError: jest.fn(),
};
const response = await appleAuthHelpers.signIn(input);
expect(input.onError.mock.calls[0][0]).toEqual(expect.any(Error));
expect(input.onError.mock.calls[0][0].message).toEqual('test error');
expect(response).toBeNull();
});

it('should return undefined and call onError if apple init throws', async () => {
window.AppleID = {
auth: {
init: () => {
throw new Error('test error');
},
signIn: AppleIDAuthSignInFn,
},
};
const input = {
authOptions: _authOptions,
onError: jest.fn(),
};
const response = await appleAuthHelpers.signIn(input);
expect(response).toBeNull();
expect(input.onError.mock.calls[0][0]).toEqual(expect.any(Error));
});

it('should return undefined and log error if apple signIn throws', async () => {
window.AppleID = {
auth: {
init: AppleIDAuthInitFn,
signIn: () => Promise.reject(new Error('test error')),
},
};
const input = {
authOptions: _authOptions,
};
const response = await appleAuthHelpers.signIn(input);
expect(response).toBeNull();
});

it('should return undefined and log error if apple init throws', async () => {
window.AppleID = {
auth: {
init: () => {
throw new Error('test error');
},
signIn: AppleIDAuthSignInFn,
},
};
const input = {
authOptions: _authOptions,
};
const response = await appleAuthHelpers.signIn(input);
expect(response).toBeNull();
});

it('should call onSuccess upon success', async () => {
const input = {
authOptions: _authOptions,
Expand Down
38 changes: 20 additions & 18 deletions src/appleAuthHelpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@ const signIn = ({
/** Init apple auth */
window.AppleID.auth.init(authOptions);
/** Signin to appleID */
window.AppleID.auth.signIn().then((response) => {
/** This is only called in case usePopup is true */
if (onSuccess) {
onSuccess(response);
}
/** resolve with the reponse */
return response;
}).catch((err) => {
if (onError) {
/** Call onError catching the error */
onError(err);
} else {
/** Log the error to help debug */
console.error(err);
}

return null;
});
return window.AppleID.auth
.signIn()
.then((response) => {
/** This is only called in case usePopup is true */
if (onSuccess) {
onSuccess(response);
}
/** resolve with the reponse */
return response;
})
.catch((err) => {
if (onError) {
/** Call onError catching the error */
onError(err);
} else {
/** Log the error to help debug */
console.error(err);
}
return null;
});
})
.catch((err) => {
if (onError) {
Expand Down

0 comments on commit 364f654

Please sign in to comment.