Latest
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535import {expect} from '@esm-bundle/chai';import {scanInfoMatchesKey} from './subscriptions';
test('scanInfoMatchesKey', () => { expect(scanInfoMatchesKey({options: {}}, '', 'a')).to.be.true; expect(scanInfoMatchesKey({options: {indexName: 'idx'}}, 'idx', 'a')).to.be .true; expect(scanInfoMatchesKey({options: {indexName: 'idx'}}, '', 'a')).to.be .false; expect(scanInfoMatchesKey({options: {}}, 'idx', 'a')).to.be.false;
expect(scanInfoMatchesKey({options: {prefix: 'p'}}, '', 'a')).to.be.false;
expect(scanInfoMatchesKey({options: {startKey: 'sk'}}, '', 'a')).to.be.false; expect(scanInfoMatchesKey({options: {startKey: 'sk'}}, '', 'skate')).to.be .true; expect(scanInfoMatchesKey({options: {startKey: 'a'}}, '', 'b')).to.be.true;
expect( scanInfoMatchesKey( {options: {prefix: 'a', indexName: 'idx'}}, 'idx', '\u0000a\u0000b', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sb', indexName: 'idx'}}, 'idx', '\u0000sa\u0000p', ), ).to.be.false;
expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab'}}, 'idx', '\u0000sab\u0000p', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab'}}, 'idx', '\u0000sac\u0000p', ), ).to.be.true; expect( scanInfoMatchesKey( {options: {prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sac'}}, 'idx', '\u0000sab\u0000p', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pa', }, }, 'idx', '\u0000sac\u0000pa', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pab', }, }, 'idx', '\u0000sac\u0000pab', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pab', }, }, 'idx', '\u0000sac\u0000pac', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'sa', indexName: 'idx', startSecondaryKey: 'sab', startKey: 'pac', }, }, 'idx', '\u0000sac\u0000pab', ), ).to.be.false;});
test('scanInfoMatchesKey limit optimizations', () => { // Start key tests // Changed key is equal to inclusive start key expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac2', ), ).to.be.true;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac2', ), ).to.be.true;
// Changed key is after start key, no inclusive limit key expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac4', ), ).to.be.true;
// Changed key is between inclusive start and inclusive limit keys expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac4', ), ).to.be.true;
// Changed key is equal to inclusive limit key expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac8', ), ).to.be.true;
// Changed key is after inclusive limit expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.false;
// Changed key is before start key expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, }, '', 'pac1', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac1', ), ).to.be.false;
// Changed key is equal to exclusive start key expect( scanInfoMatchesKey( { options: { startKey: 'pac2', startExclusive: true, limit: 10, }, }, '', 'pac2', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { startKey: 'pac2', startExclusive: true, limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac2', ), ).to.be.false;
// No limit expect( scanInfoMatchesKey( { options: { startKey: 'pac2', }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.true;
// Prefix tests // Changed key matches prefix and is less than inclusive limit key expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac1', ), ).to.be.true;
// Changed key matches prefix and equals inclusive limit key expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac8', ), ).to.be.true;
// Changed key matches prefix but is after inclusive limit expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.false;
// Changed key doesn't match prefix but is less than inclusive limit expect( scanInfoMatchesKey( { options: { prefix: 'pac', limit: 10, }, inclusiveLimitKey: 'pac8', }, '', 'pab', ), ).to.be.false;
// No limit expect( scanInfoMatchesKey( { options: { prefix: 'pac', }, inclusiveLimitKey: 'pac8', }, '', 'pac9', ), ).to.be.true;
// Start and prefix tests // Changed key is equal to inclusive start key and matches prefix expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac22', ), ).to.be.true; expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac22', ), ).to.be.true;
// Changed key is after start key and matches prefix, no inclusive limit key expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac24', ), ).to.be.true;
// Changed key is between inclusive start and inclusive limit keys and matches prefix expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac24', ), ).to.be.true;
// Changed key is equal to inclusive limit key and matches prefix expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac28', ), ).to.be.true;
// Changed key match prefix but is after inclusive limit expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac29', ), ).to.be.false;
// Changed key matches prefix but is before start key expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, }, '', 'pac21', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac21', ), ).to.be.false;
// Changed key is equal to exclusive start key expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', startExclusive: true, limit: 10, }, }, '', 'pac22', ), ).to.be.false;
expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', startExclusive: true, limit: 10, }, inclusiveLimitKey: 'pac28', }, '', 'pac22', ), ).to.be.false;
// No limit expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pac22', }, inclusiveLimitKey: 'pac28', }, '', 'pac29', ), ).to.be.true;
// Changed key is between startKey and lastKey inclusive, but doesnt match prefix expect( scanInfoMatchesKey( { options: { prefix: 'pac2', startKey: 'pab1', }, inclusiveLimitKey: 'pac28', }, '', 'pab2', ), ).to.be.false;});