Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds RTDB triggers for v2 functions #1127

Merged
merged 17 commits into from Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
- Adds RTDB Triggers for v2 functions (#1127)
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -65,7 +65,8 @@
"./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
"./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js",
"./v2/eventarc": "./lib/v2/providers/eventarc.js",
"./v2/identity": "./lib/v2/providers/identity.js"
"./v2/identity": "./lib/v2/providers/identity.js",
"./v2/database": "./lib/v2/providers/database.js"
},
"typesVersions": {
"*": {
Expand Down Expand Up @@ -126,6 +127,9 @@
"v2/base": [
"lib/v2/base"
],
"v2/database": [
"lib/v2/providers/database"
],
"v2/eventarc": [
"lib/v2/providers/eventarc"
],
Expand Down
145 changes: 145 additions & 0 deletions spec/utilities/path-pattern.spec.ts
@@ -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',
});
});
});
});