Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const rp = require('request-promise');
const jsonDiff = require('json-diff');
admin.initializeApp();
// [START remote_config_function]
exports.showConfigDiff = functions.remoteConfig.onUpdate(versionMetadata => {
return admin.credential.applicationDefault().getAccessToken()
.then(accessTokenObj => {
return accessTokenObj.access_token;
})
.then(accessToken => {
const currentVersion = versionMetadata.versionNumber;
const templatePromises = [];
templatePromises.push(getTemplate(currentVersion, accessToken));
templatePromises.push(getTemplate(currentVersion - 1, accessToken));
return Promise.all(templatePromises);
})
.then(results => {
const currentTemplate = results[0];
const previousTemplate = results[1];
import * as functions from 'firebase-functions';
import { expectEq, TestSuite } from './testing';
import TemplateVersion = functions.remoteConfig.TemplateVersion;
export const remoteConfigTests: any = functions.remoteConfig.onUpdate(
(v, c) => {
return new TestSuite('remoteConfig onUpdate')
.it('should have a project as resource', (version, context) =>
expectEq(
context.resource.name,
`projects/${process.env.GCLOUD_PROJECT}`
)
)
.it('should have the correct eventType', (version, context) =>
expectEq(context.eventType, 'google.firebase.remoteconfig.update')
)
.it('should have an eventId', (version, context) => context.eventId)
.it('should have a timestamp', (version, context) => context.timestamp)