Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await sendRequestToJoinGroup(pluto, selenitesGroup); // request from non-friend
const whoAmI = await fetch(`${app.context.config.host}/v2/users/whoami`, { headers: { 'X-Authentication-Token': luna.authToken } }).then((r) => r.json());
const managedGroupSchema = {
...schema.group,
requests: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', schema.user),
};
const thisUserSchema = {
...schema.user,
email: expect.it('to be a string'),
privateMeta: expect.it('to be an object'),
frontendPreferences: expect.it('to be an object'),
banIds: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.UUID),
pendingGroupRequests: expect.it('to be a boolean'),
pendingSubscriptionRequests: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.UUID),
subscriptionRequests: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.UUID),
unreadDirectsNumber: expect.it('to be a string').and('to match', /^\d+$/),
unreadNotificationsNumber: expect.it('to be a number'),
subscribers: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', schema.user),
subscriptions: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.UUID),
preferences: expect.it('to satisfy', (data) => expect(validateUserPrefs(data), 'to be an object')),
};
expect(whoAmI, 'to exhaustively satisfy', {
users: thisUserSchema,
subscribers: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', schema.userOrGroup),
subscriptions: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', {
id: expect.it('to satisfy', schema.UUID),
name: expect.it('to be a string'),
user: expect.it('to be a string'),
/* eslint-env node, mocha */
import unexpected from 'unexpected';
import unexpectedMoment from 'unexpected-moment';
import moment from 'moment';
import { shouldSendDailyBestOfDigest, shouldSendWeeklyBestOfDigest, canMakeBestOfEmail } from '../../../app/support/BestOfDigest';
const expect = unexpected.clone()
.use(unexpectedMoment);
describe('BestOfDigest', () => {
describe('shouldSendDailyBestOfDigest()', () => {
const someTimeAgo = '2017-12-28T00:00:00.000Z';
const now = '2018-01-01T00:00:00.000Z';
describe('if weekly digest has never been sent previously', () => {
describe('if daily digest has never been sent previously', () => {
it('should send daily summary email', async () => {
await expect(shouldSendDailyBestOfDigest(null, undefined, now), 'to be', true);
await expect(shouldSendDailyBestOfDigest(undefined, undefined, now), 'to be', true);
});
});
describe('if sent several days ago', () => {
export async function fetchTimeline(path, viewerContext = null) {
const headers = {};
if (viewerContext) {
headers['X-Authentication-Token'] = viewerContext.authToken;
}
const response = await fetch(
await apiUrl(`/v2/timelines/${path}`),
{ agent, headers }
);
const feed = await response.json();
// console.log(feed);
if (response.status !== 200) {
expect.fail('HTTP error (code {0}): {1}', response.status, feed.err);
}
expect(feed, 'to exhaustively satisfy', schema.timelineResponse);
return feed;
}
async function fetchEverything(viewerContext = null) {
const headers = {};
if (viewerContext) {
headers['X-Authentication-Token'] = viewerContext.authToken;
}
const response = await performRequest(`/v2/everything`, { headers });
const feed = await response.json();
// console.log(feed);
if (response.status !== 200) {
expect.fail('HTTP error (code {0}): {1}', response.status, feed.err);
}
expect(feed, 'to exhaustively satisfy', schema.everythingResponse);
return feed;
}
const { default: runProgram } = require("./utils/runProgram");
const generateProject = require("./utils/generateProject");
const expect = require("unexpected");
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const chalk = require("chalk");
expect.addAssertion(
" when run ",
async (expect, cmd, assertion, compare) => {
const result = await exec(cmd);
return result.stderr
? expect.fail(new Error(`Command errored: ${result.sdterr}`))
: expect(result.stdout.trim(), assertion, compare);
}
);
describe("Git features", async () => {
it("correctly adds git commit and branch", async () => {
// eslint-disable-next-line
jest.setTimeout(100000);
const projectPath = await generateProject({
name: "project-a",
git: true,
const expectFolding = async (nComments, expComments, expOmitted, allComments = false) => {
for (let n = 0; n < nComments; n++) {
await createCommentAsync(luna, lunaPost.id, `Comment ${n + 1}`); // eslint-disable-line no-await-in-loop
}
const post = await fetchPost(lunaPost.id, null, { allComments });
expect(post.posts.comments, 'to have length', expComments);
expect(post.posts.omittedComments, 'to equal', expOmitted);
};
/* global describe, it */
const sinon = require('sinon');
const expect = require('unexpected')
.clone()
.use(require('unexpected-sinon'));
const subfont = require('../lib/subfont');
const httpception = require('httpception');
const proxyquire = require('proxyquire');
const pathModule = require('path');
const openSansBold = require('fs').readFileSync(
pathModule.resolve(
__dirname,
'..',
'testdata',
'k3k702ZOKiLJc3WVjuplzHhCUOGz7vYGh680lGh-uXM.woff'
)
);
describe('subfont', function() {
/*global global*/
import jsdom from "jsdom";
import expect from "unexpected";
import unexpectedSinon from "unexpected-sinon";
import sinon from "sinon";
// Set up expected browser globals.
global.document = jsdom.jsdom("");
global.window = document.defaultView;
global.navigator = {
userAgent: ""
};
// Set up Unexpected plugins (on the actual unexpected instance, so they show up when it is imported by other modules).
expect.installPlugin(unexpectedSinon);
// Automatically restore Sinon stubs after tests end.
var oldWrap = sinon.wrapMethod;
var wrappeds = [];
var afterSetup = false;
sinon.wrapMethod = function (...args) {
var out = oldWrap.apply(sinon, args);
wrappeds.push(out);
if (!afterSetup) {
// Delay setting up afterEach since it is not yet defined when this module is run.
afterEach(() => {
wrappeds.forEach(wrapped => {
wrapped.restore();
});
wrappeds = [];
});
require("babel-register");
var unexpected = require('unexpected');
unexpected.use(require('unexpected-sinon'));
unexpected.use(require('unexpected-set'));
var Bluebird = require('bluebird');
require('sinon-as-promised')(Bluebird);
var Sequelize = require('sequelize');
unexpected.addType({
name: 'Sequelize.Instance',
identify: /^[45]/.test(Sequelize.version) ?
function (value) {
return value && value instanceof Sequelize.Model && 'isNewRecord' in value;
} :
function (value) {
return value && value instanceof Sequelize.Instance;
},
inspect: function (value, depth, output, inspect) {
const name = value.name || value.$modelOptions.name || value._modelOptions.name; // v3 vs v4
inspect: function (value, depth, output, inspect) {
const name = value.name || value.$modelOptions.name || value._modelOptions.name; // v3 vs v4
output
.text(name.singular).text('(')
.append(inspect(value.get(), depth))
.text(')');
},
equal: function (a, b) {
const aModel = a.Model || a.constructor; // v3 vs v4
const bModel = b.Model || b.constructor;
const pk = aModel.primaryKeyAttribute;
return aModel.name === bModel.name && a.get(pk) === b.get(pk);
}
});
unexpected.addType({
name: 'Sequelize.Association',
identify: function (value) {
return value && value instanceof Sequelize.Association;
},
inspect: function (value, depth, output) {
output
.text(value.associationType).text(': ')
.text(value.source.name).text(' -> ').text(value.target.name)
.text('(').text(value.as).text(')');
},
equal: function (a, b, equal) {
return a.associationType === b.associationType && equal(a.source, b.source) && equal(a.target, b.target) && a.as === b.as;
}
});
unexpected.addAssertion(' [not] to be shimmed', function (expect, subject) {