-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds RTDB triggers for v2 functions (#1127)
* moving DataSnapshot to common, removing lodash, and adding in initial v2 interface and logic * fixing tests * normalize path & remove commented structure * changing default rtdb url * defualt to * instances and export everything correctly * linter * fixed parsing for multi segments and adding in tests * update tsdoc comments and add changelog * fixing export path * cleaning up params code * ref is always a path pattern * addressing comments and creating path pattern class * linter * adding describe block * adding in changes from @rhodgkins to match the admin SDK * linter
- Loading branch information
1 parent
40f0b43
commit e42fe3a
Showing
11 changed files
with
1,816 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Adds RTDB Triggers for v2 functions (#1127) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2022 Firebase | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
import { expect } from 'chai'; | ||
import * as pathPattern from '../../src/utilities/path-pattern'; | ||
|
||
describe('path-pattern', () => { | ||
describe('trimParam', () => { | ||
it('should trim a capture param without equals', () => { | ||
expect(pathPattern.trimParam('{something}')).to.equal('something'); | ||
}); | ||
|
||
it('should trim a capture param with equals', () => { | ||
expect(pathPattern.trimParam('{something=*}')).to.equal('something'); | ||
}); | ||
}); | ||
|
||
describe('extractMatches', () => { | ||
it('should parse without multi segment', () => { | ||
const pp = new pathPattern.PathPattern('{a}/something/else/{b}/end/{c}'); | ||
|
||
expect( | ||
pp.extractMatches('match_a/something/else/match_b/end/match_c') | ||
).to.deep.equal({ | ||
a: 'match_a', | ||
b: 'match_b', | ||
c: 'match_c', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment with params after', () => { | ||
const pp = new pathPattern.PathPattern( | ||
'something/**/else/{a}/hello/{b}/world' | ||
); | ||
|
||
expect( | ||
pp.extractMatches('something/is/a/thing/else/nothing/hello/user/world') | ||
).to.deep.equal({ | ||
a: 'nothing', | ||
b: 'user', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment param with params after', () => { | ||
const pp = new pathPattern.PathPattern( | ||
'something/{path=**}/else/{a}/hello/{b}/world' | ||
); | ||
|
||
expect( | ||
pp.extractMatches('something/is/a/thing/else/nothing/hello/user/world') | ||
).to.deep.equal({ | ||
path: 'is/a/thing', | ||
a: 'nothing', | ||
b: 'user', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment with params before', () => { | ||
const pp = new pathPattern.PathPattern('{a}/something/{b}/**/end'); | ||
|
||
expect( | ||
pp.extractMatches( | ||
'match_a/something/match_b/thing/else/nothing/hello/user/end' | ||
) | ||
).to.deep.equal({ | ||
a: 'match_a', | ||
b: 'match_b', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment param with params before', () => { | ||
const pp = new pathPattern.PathPattern('{a}/something/{b}/{path=**}/end'); | ||
|
||
expect( | ||
pp.extractMatches( | ||
'match_a/something/match_b/thing/else/nothing/hello/user/end' | ||
) | ||
).to.deep.equal({ | ||
a: 'match_a', | ||
b: 'match_b', | ||
path: 'thing/else/nothing/hello/user', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment with params before and after', () => { | ||
const pp = new pathPattern.PathPattern('{a}/something/**/{b}/end'); | ||
|
||
expect( | ||
pp.extractMatches( | ||
'match_a/something/thing/else/nothing/hello/user/match_b/end' | ||
) | ||
).to.deep.equal({ | ||
a: 'match_a', | ||
b: 'match_b', | ||
}); | ||
}); | ||
|
||
it('should parse multi segment param with params before', () => { | ||
const pp = new pathPattern.PathPattern('{a}/something/{path=**}/{b}/end'); | ||
|
||
expect( | ||
pp.extractMatches( | ||
'match_a/something/thing/else/nothing/hello/user/match_b/end' | ||
) | ||
).to.deep.equal({ | ||
a: 'match_a', | ||
b: 'match_b', | ||
path: 'thing/else/nothing/hello/user', | ||
}); | ||
}); | ||
|
||
// handle an instance param | ||
it('should parse an instance', () => { | ||
const pp = new pathPattern.PathPattern('{a}-something-{b}-else-{c}'); | ||
|
||
expect( | ||
pp.extractMatches('match_a-something-match_b-else-match_c') | ||
).to.deep.equal({}); | ||
|
||
const anotherPP = new pathPattern.PathPattern('{a}'); | ||
|
||
expect(anotherPP.extractMatches('match_a')).to.deep.equal({ | ||
a: 'match_a', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.