id-generator.test.js 542 B

123456789101112131415161718192021
  1. 'use strict'
  2. const { test } = require('tap')
  3. const { MAX_MSGID } = require('../../../../lib/client/constants')
  4. const idGeneratorFactory = require('../../../../lib/client/message-tracker/id-generator')
  5. test('starts at 0', async t => {
  6. const nextID = idGeneratorFactory()
  7. const currentID = nextID()
  8. t.equal(currentID, 1)
  9. })
  10. test('handles wrapping around', async t => {
  11. const nextID = idGeneratorFactory(MAX_MSGID - 2)
  12. let currentID = nextID()
  13. t.equal(currentID, MAX_MSGID - 1)
  14. currentID = nextID()
  15. t.equal(currentID, 1)
  16. })