diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 954286946..b3ffe8b03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,3 +29,12 @@ jobs: run: | npm ci npm t + + - name: Test & publish code coverage + uses: paambaati/codeclimate-action@v3.0.0 + env: + CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}} + with: + coverageCommand: yarn run coverage + coverageLocations: | + ${{github.workspace}}/test/coverage/lcov.info:lcov diff --git a/jest.config.js b/jest.config.js index 87c30aa4a..77e52e1a7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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/**', + ], } diff --git a/test/apiWithAutoConfirmEnabled.test.ts b/test/apiWithAutoConfirmEnabled.test.ts new file mode 100644 index 000000000..53fb85723 --- /dev/null +++ b/test/apiWithAutoConfirmEnabled.test.ts @@ -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, + "expires_at": Any, + "expires_in": 3600, + "refresh_token": Any, + "token_type": "bearer", + "user": Object { + "app_metadata": Object { + "provider": "email", + "providers": Array [ + "email", + ], + }, + "aud": "", + "created_at": Any, + "email": Any, + "email_confirmed_at": Any, + "id": Any, + "identities": Array [], + "last_sign_in_at": Any, + "phone": "", + "role": "", + "updated_at": Any, + "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, + "created_at": Any, + "email": Any, + "email_confirmed_at": Any, + "id": Any, + "identities": Array [], + "last_sign_in_at": Any, + "phone": "", + "role": "", + "updated_at": Any, + "user_metadata": Object { + "status": "alpha", + }, + } + ` + ) +})