Skip to content

Commit

Permalink
Merge pull request #173 from Meteor-Community-Packages/feature/update…
Browse files Browse the repository at this point in the history
…-tests

Update tests
  • Loading branch information
StorytellerCZ committed Feb 22, 2024
2 parents 78004b5 + 0355d45 commit 57ca2f5
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 126 deletions.
37 changes: 36 additions & 1 deletion .npm/package/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions lib/doc_ref_counter.js
@@ -1,19 +1,21 @@
import { valueOfId } from './utils'

class DocumentRefCounter {
constructor (observer) {
this.heap = {}
this.observer = observer
}

increment (collectionName, docId) {
const key = `${collectionName}:${docId.valueOf()}`
const key = `${collectionName}:${valueOfId(docId)}`
if (!this.heap[key]) {
this.heap[key] = 0
}
this.heap[key] += 1
}

decrement (collectionName, docId) {
const key = `${collectionName}:${docId.valueOf()}`
const key = `${collectionName}:${valueOfId(docId)}`
if (this.heap[key]) {
this.heap[key] -= 1

Expand Down
2 changes: 1 addition & 1 deletion lib/publication.js
Expand Up @@ -31,7 +31,7 @@ class Publication {
// Use Meteor.bindEnvironment to make sure the callbacks are run with the same
// environmentVariables as when publishing the "parent".
// It's only needed when publish is being recursively run.
this.observeHandle = this.cursor.observe({
this.observeHandle = await this.cursor.observe({
added: Meteor.bindEnvironment(async (doc) => {
const addedPromise = new Promise((resolve, reject) => {
// call the async function to handle the 'added' logic
Expand Down
19 changes: 5 additions & 14 deletions lib/published_document_list.js
@@ -1,12 +1,13 @@
import PublishedDocument from './published_document'
import { valueOfId } from './utils'

class PublishedDocumentList {
constructor () {
this.documents = {}
}

add (collectionName, docId) {
const key = valueOfId(docId)
const key = valueOfId(docId, true)

if (!this.documents[key]) {
this.documents[key] = new PublishedDocument(collectionName, docId)
Expand All @@ -16,7 +17,7 @@ class PublishedDocumentList {
addChildPub (docId, publication) {
if (!publication) { return }

const key = valueOfId(docId)
const key = valueOfId(docId, true)
const doc = this.documents[key]

if (typeof doc === 'undefined') {
Expand All @@ -27,12 +28,12 @@ class PublishedDocumentList {
}

get (docId) {
const key = valueOfId(docId)
const key = valueOfId(docId, true)
return this.documents[key]
}

remove (docId) {
const key = valueOfId(docId)
const key = valueOfId(docId, true)
delete this.documents[key]
}

Expand Down Expand Up @@ -79,14 +80,4 @@ class PublishedDocumentList {
}
}

function valueOfId (docId) {
if (docId === null) {
throw new Error('Document ID is null')
}
if (typeof docId === 'undefined') {
throw new Error('Document ID is undefined')
}
return docId.valueOf()
}

export default PublishedDocumentList
7 changes: 4 additions & 3 deletions lib/subscription.js
@@ -1,5 +1,6 @@
import DocumentRefCounter from './doc_ref_counter'
import { debugLog } from './logging'
import { valueOfId } from './utils'

// eslint-disable-next-line
const isEqual = Npm.require('lodash.isequal')
Expand All @@ -10,7 +11,7 @@ class Subscription {
this.docHash = {}
this.refCounter = new DocumentRefCounter({
onChange: (collectionName, docId, refCount) => {
debugLog('Subscription.refCounter.onChange', `${collectionName}:${docId.valueOf()} ${refCount}`)
debugLog('Subscription.refCounter.onChange', `${collectionName}:${valueOfId(docId, true)} ${refCount}`)
if (refCount <= 0) {
meteorSub.removed(collectionName, docId)
this._removeDocHash(collectionName, docId)
Expand Down Expand Up @@ -38,7 +39,7 @@ class Subscription {
}

removed (collectionName, id) {
debugLog('Subscription.removed', `${collectionName}:${id.valueOf()}`)
debugLog('Subscription.removed', `${collectionName}:${valueOfId(id, true)}`)
this.refCounter.decrement(collectionName, id)
}

Expand Down Expand Up @@ -77,7 +78,7 @@ class Subscription {
}

function buildHashKey (collectionName, id) {
return `${collectionName}::${id.valueOf()}`
return `${collectionName}::${valueOfId(id, true)}`
}

export default Subscription
21 changes: 21 additions & 0 deletions lib/utils.js
@@ -0,0 +1,21 @@
import { Meteor } from 'meteor/meteor'
import { Log } from 'meteor/logging'

export function valueOfId (docId, doNotThrow) {
if (docId === null) {
if (doNotThrow) {
Log.debug('Document ID is null')
return ''
}
throw new Meteor.Error('Document ID is null')
}
if (typeof docId === 'undefined') {
if (doNotThrow) {
Log.debug('Document ID is undefined')
return ''
}
throw new Meteor.Error('Document ID is undefined')
}
if (typeof docId === 'string') return docId
return docId?.valueOf() || ''
}
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions package.js
@@ -1,16 +1,15 @@
/* globals Package */
/* globals Package Npm */
Package.describe({
name: 'reywood:publish-composite',
summary: 'Publish a set of related documents from multiple collections with a reactive join.',
version: '1.8.6',
git: 'https://github.com/Meteor-Community-Packages/meteor-publish-composite'
})

Npm.depends({
"lodash.isequal": "4.5.0"
})

Package.onUse((api) => {
Npm.depends({
'lodash.isequal': '4.5.0'
})
api.versionsFrom(['1.8.3', '2.8.1', '3.0-beta.0'])
api.use([
'check',
Expand All @@ -34,18 +33,22 @@ Package.onUse((api) => {
], 'server')
})

// meteor test-packages reywood:publish-composite --driver-package meteortesting:mocha
Package.onTest((api) => {
Npm.depends({
'lodash.isequal': '4.5.0',
chai: '5.0.0'
})
api.use([
'ecmascript',
'modules'
'modules',
'mongo'
], ['client', 'server'])
api.use([
'cultofcoders:mocha',
'practicalmeteor:chai'
'meteortesting:mocha-core@8.2.0-beta300.0'
], 'client')
api.use([
'reywood:publish-composite',
'mongo',
'underscore'
], 'server')

Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -39,6 +39,8 @@
"@babel/eslint-parser": "^7.22.15",
"@babel/preset-env": "^7.23.2",
"all-contributors-cli": "^6.26.1",
"chai": "^4.3.10",
"chai-as-promised": "^7.1.1",
"husky": "^8.0.3",
"lodash.isequal": "^4.5.0",
"standard": "^17.1.0"
Expand Down

0 comments on commit 57ca2f5

Please sign in to comment.