Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
test: setup jest, add some very basic tests for the Clerk object
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtallness committed Feb 1, 2021
1 parent 82c5354 commit c5e7539
Show file tree
Hide file tree
Showing 7 changed files with 972 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ jobs:
- name: Install deps and build (with cache)
uses: bahmutov/npm-install@v1

- name: Lint
run: yarn lint
# disable for now
# - name: Lint
# run: yarn lint

- name: Test
run: yarn test --ci --coverage --maxWorkers=2
Expand Down
12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
"roots": [
"<rootDir>/src"
],
"testMatch": [
"**/test/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest"
},
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@
"devDependencies": {
"@size-limit/preset-small-lib": "^4.9.1",
"@types/express": "^4.17.11",
"@types/jest": "^26.0.20",
"express": "^4.17.1",
"husky": "^4.3.7",
"jest": "^26.6.3",
"next": "^10.0.5",
"size-limit": "^4.9.1",
"ts-jest": "^26.5.0",
"tsdx": "^0.14.1",
"tslib": "^2.1.0",
"typescript": "^4.1.3"
Expand Down Expand Up @@ -78,5 +81,6 @@
"homepage": "https://github.com/clerkinc/clerk-sdk-node#readme",
"publishConfig": {
"access": "public"
}
},
"test": "jest"
}
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ export {
RequireSessionProp,
} from './instance';

// Export a default singleton instance that should suffice for most use cases
const singletonInstance = Clerk.getInstance();
export default singletonInstance;
const clients = singletonInstance.clients;
const emails = singletonInstance.emails;
const sessions = singletonInstance.sessions;
const smsMessages = singletonInstance.smsMessages;
const users = singletonInstance.users;

// Export a default singleton instance that should suffice for most use cases
export default singletonInstance;

// Export sub-api objects
export { clients, emails, sessions, smsMessages, users };

Expand Down
78 changes: 78 additions & 0 deletions src/test/Clerk_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import Clerk from '../Clerk';
import { ClientApi } from '../apis/ClientApi';
import { EmailApi } from '../apis/EmailApi';
import { SessionApi } from '../apis/SessionApi';
import { SMSMessageApi } from '../apis/SMSMessageApi';
import { UserApi } from '../apis/UserApi';

test('getInstance() getter returns a Clerk instance', () => {
const clerk = Clerk.getInstance();
expect(clerk).toBeInstanceOf(Clerk);
});

test('getInstance() always returns the same instance', () => {
const clerk = Clerk.getInstance();
const clerk2 = Clerk.getInstance();
expect(clerk2).toBe(clerk);
});

test('separate Clerk instances are not the same object', () => {
const clerk = new Clerk();
const clerk2 = new Clerk();
expect(clerk2).not.toBe(clerk);
});

test('clients getter returns a Client API instance', () => {
const clients = Clerk.getInstance().clients;
expect(clients).toBeInstanceOf(ClientApi);
});

test('clients getter returns the same instance every time', () => {
const clients = Clerk.getInstance().clients;
const clients2 = Clerk.getInstance().clients;
expect(clients2).toBe(clients);
});

test('emails getter returns a Email API instance', () => {
const emails = Clerk.getInstance().emails;
expect(emails).toBeInstanceOf(EmailApi);
});

test('emails getter returns the same instance every time', () => {
const emails = Clerk.getInstance().emails;
const emails2 = Clerk.getInstance().emails;
expect(emails2).toBe(emails);
});

test('sessions getter returns a Session API instance', () => {
const sessions = Clerk.getInstance().sessions;
expect(sessions).toBeInstanceOf(SessionApi);
});

test('sessions getter returns the same instance every time', () => {
const sessions = Clerk.getInstance().sessions;
const sessions2 = Clerk.getInstance().sessions;
expect(sessions2).toBe(sessions);
});

test('smsMessages getter returns an smsMessage API instance', () => {
const smsMessages = Clerk.getInstance().smsMessages;
expect(smsMessages).toBeInstanceOf(SMSMessageApi);
});

test('smsMessages getter returns the same instance every time', () => {
const smsMessages = Clerk.getInstance().smsMessages;
const smsMessages2 = Clerk.getInstance().smsMessages;
expect(smsMessages2).toBe(smsMessages);
});

test('users getter returns a User api instance', () => {
const users = Clerk.getInstance().users;
expect(users).toBeInstanceOf(UserApi);
});

test('users getter returns the same instance every time', () => {
const users = Clerk.getInstance().users;
const users2 = Clerk.getInstance().users;
expect(users2).toBe(users);
});
1 change: 1 addition & 0 deletions src/utils/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO use EventEmitter for an async Logger instead
// TODO use actual console log levels

enum LogLevel {
Info = 'INFO',
Expand Down
Loading

0 comments on commit c5e7539

Please sign in to comment.