Skip to content

Commit

Permalink
increases coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwicopple committed Nov 18, 2021
1 parent 8e71574 commit 98300a0
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,12 @@ jobs:
run: |
npm ci
npm t
- name: Test & publish code coverage
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
with:
coverageCommand: yarn run coverage
coverageLocations: |
${{github.workspace}}/test/coverage/lcov.info:lcov
10 changes: 10 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
collectCoverage: true,
coverageDirectory: './test/coverage',
coverageReporters: ['json', 'html', 'lcov'],
collectCoverageFrom: [
'./src/**/*.{js,ts}',
'./src/**/*.unit.test.ts',
'!**/node_modules/**',
'!**/vendor/**',
'!**/vendor/**',
],
}
109 changes: 109 additions & 0 deletions test/apiWithAutoConfirmEnabled.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { GoTrueApi, Session } from '../src/index'
import faker from 'faker'

const GOTRUE_URL = 'http://localhost:9998'

const api = new GoTrueApi({
url: GOTRUE_URL,
headers: {
Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.0sOtTSTfPv5oPZxsjvBO249FI4S4p0ymHoIZ6H6z9Y8`,
},
})

const email = `api_ac_enabled_${faker.internet.email().toLowerCase()}`
const password = faker.internet.password()
let validSession: Session | null = null

test('signUpWithEmail()', async () => {
const { error, data } = await api.signUpWithEmail(email, password, {
data: { status: 'alpha' },
})
validSession = data as Session
expect(error).toBeNull()
expect(data).toMatchInlineSnapshot(
{
access_token: expect.any(String),
expires_at: expect.any(Number),
refresh_token: expect.any(String),
user: {
id: expect.any(String),
created_at: expect.any(String),
email: expect.any(String),
updated_at: expect.any(String),
last_sign_in_at: expect.any(String),
email_confirmed_at: expect.any(String),
},
},
`
Object {
"access_token": Any<String>,
"expires_at": Any<Number>,
"expires_in": 3600,
"refresh_token": Any<String>,
"token_type": "bearer",
"user": Object {
"app_metadata": Object {
"provider": "email",
"providers": Array [
"email",
],
},
"aud": "",
"created_at": Any<String>,
"email": Any<String>,
"email_confirmed_at": Any<String>,
"id": Any<String>,
"identities": Array [],
"last_sign_in_at": Any<String>,
"phone": "",
"role": "",
"updated_at": Any<String>,
"user_metadata": Object {
"status": "alpha",
},
},
}
`
)
})

test('getUser()', async () => {
const { error, data } = await api.getUser(validSession?.access_token || '')
expect(error).toBeNull()

expect(data).toMatchInlineSnapshot(
{
id: expect.any(String),
created_at: expect.any(String),
email: expect.any(String),
updated_at: expect.any(String),
last_sign_in_at: expect.any(String),
email_confirmed_at: expect.any(String),
confirmed_at: expect.any(String),
},
`
Object {
"app_metadata": Object {
"provider": "email",
"providers": Array [
"email",
],
},
"aud": "",
"confirmed_at": Any<String>,
"created_at": Any<String>,
"email": Any<String>,
"email_confirmed_at": Any<String>,
"id": Any<String>,
"identities": Array [],
"last_sign_in_at": Any<String>,
"phone": "",
"role": "",
"updated_at": Any<String>,
"user_metadata": Object {
"status": "alpha",
},
}
`
)
})

0 comments on commit 98300a0

Please sign in to comment.