Skip to content

Commit

Permalink
Merge pull request #20 from leaonline/tests/model-coverage
Browse files Browse the repository at this point in the history
Tests/model coverage
  • Loading branch information
jankapunkt authored Jul 2, 2024
2 parents c200242 + bee0d78 commit c6fbd6f
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 12 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,43 @@ on:
pull_request:

jobs:
lint:
name: StandardJS lint
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Cache NPM dependencies
id: cache-npm
uses: actions/cache@v4
with:
path: ~/.npm
key: v3-npm-${{ hashFiles('package-lock.json') }}
restore-keys: |
v3-npm-
- name: Run lint
run: |
cd test-proxy
npm install
npm run setup
npm run lint
tests:
name: Meteor tests
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

# CACHING
- name: Install Meteor
id: cache-meteor-install
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.meteor
key: v3-meteor-${{ hashFiles('.meteor/versions') }}
Expand Down Expand Up @@ -52,10 +78,9 @@ jobs:
with:
meteor-release: '2.8.1'

- name: Run lint and tests
- name: Run tests
run: |
cd test-proxy
meteor npm install
meteor npm run setup
meteor npm run lint
meteor npm run test
52 changes: 47 additions & 5 deletions tests/model-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Meteor } from 'meteor/meteor'
import { Mongo } from 'meteor/mongo'
import { Random } from 'meteor/random'
import { assert } from 'meteor/practicalmeteor:chai'
import { assert, expect } from 'chai'
import { OAuthMeteorModel } from '../lib/model/model'
import { DefaultModelConfig } from '../lib/model/DefaultModelConfig'

Expand Down Expand Up @@ -33,6 +33,13 @@ describe('model', function () {
randomClientsName = Random.id()
})

afterEach(function () {
Mongo.Collection.get(DefaultModelConfig.clientsCollectionName).remove({})
Mongo.Collection.get(DefaultModelConfig.accessTokensCollectionName).remove({})
Mongo.Collection.get(DefaultModelConfig.refreshTokensCollectionName).remove({})
Mongo.Collection.get(DefaultModelConfig.authCodesCollectionName).remove({})
})

describe('constructor', function () {
it('can be created with defaults', function () {
assert.isDefined(new OAuthMeteorModel())
Expand Down Expand Up @@ -154,13 +161,48 @@ describe('model', function () {
})

describe('saveToken', function () {
it('saves an access token')
it('optionally saves a refresh token')
it('optionally allows to assign extended values')
let model

beforeEach(function () {
model = new OAuthMeteorModel()
})

it('saves an access token', async () => {
const insertTokenDoc = {
accessToken: Random.id(),
accessTokenExpiresAt: new Date(),
refreshToken: Random.id(),
refreshTokenExpiresAt: new Date(),
scope: ['foo', 'bar']
}
const clientDoc = { clientId: Random.id() }
const userDoc = { id: Random.id() }
const tokenDoc = await model.saveToken(insertTokenDoc, clientDoc, userDoc)
expect(tokenDoc).to.deep.equal({
...tokenDoc,
client: { id: clientDoc.clientId },
user: userDoc
})
})
})

describe('getAccessToken', function () {
it('returns a saved token')
let model

beforeEach(function () {
model = new OAuthMeteorModel()
})

it('returns a saved token', async () => {
const collection = Mongo.Collection.get(DefaultModelConfig.accessTokensCollectionName)
const accessToken = Random.id()
const docId = collection.insert({ accessToken })
const tokenDoc = await model.getAccessToken(accessToken)
expect(tokenDoc).to.deep.equal({
_id: docId,
accessToken
})
})
})

describe('saveAuthorizationCode', function () {
Expand Down
7 changes: 4 additions & 3 deletions tests/oauth-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ describe('integration tests of OAuth2 workflows', function () {
})
}

const ClientCollection = Mongo.Collection.get(DefaultModelConfig.clientsCollectionName)
let ClientCollection
let clientDoc
let user

beforeEach(function () {
const clientDocId = authCodeServer.registerClient({
beforeEach(async function () {
ClientCollection = Mongo.Collection.get(DefaultModelConfig.clientsCollectionName)
const clientDocId = await authCodeServer.registerClient({
title: Random.id(),
redirectUris: [Meteor.absoluteUrl(`/${Random.id()}`)],
grants: ['authorization_code']
Expand Down

0 comments on commit c6fbd6f

Please sign in to comment.