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'),
export const comment = (obj) => {
const isHidden = obj && typeof obj === 'object' && obj.hideType !== Comment.VISIBLE;
const createdByExpectation = isHidden ? expect.it('to be null') : expect.it('to satisfy', UUID);
return expect(obj, 'to exhaustively satisfy', {
...commentBasic,
createdBy: createdByExpectation,
});
};
};
export const UUID = (v) => expect(v, 'to match', /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-(8|9|a|b)[a-f0-9]{3}-[a-f0-9]{12}$/);
export const userBasic = {
id: expect.it('to satisfy', UUID),
username: expect.it('to be a string'),
screenName: expect.it('to be a string'),
isPrivate: expect.it('to satisfy', boolString),
isProtected: expect.it('to satisfy', boolString),
createdAt: expect.it('to satisfy', timeStampString),
updatedAt: expect.it('to satisfy', timeStampString),
type: expect.it('to equal', 'user'),
description: expect.it('to be a string'),
profilePictureLargeUrl: expect.it('to be a string'),
profilePictureMediumUrl: expect.it('to be a string'),
};
export const groupBasic = {
...userBasic,
isRestricted: expect.it('to satisfy', boolString),
type: expect.it('to equal', 'group'),
};
export const user = {
...userBasic,
statistics: expect.it('to be an object'),
};
export const group = {
...groupBasic,
statistics: expect.it('to be an object'),
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'),
}),
requests: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', schema.userOrGroup),
managedGroups: expect.it('to be an array').and('to be empty').or('to have items exhaustively satisfying', managedGroupSchema),
});
});
createdBy: expect.it('to satisfy', UUID),
mediaType: expect.it('to be one of', ['image', 'audio', 'general']),
fileName: expect.it('to be a string'),
fileSize: expect.it('to be a string').and('to match', /^\d+$/),
imageSizes: expect.it('to be an object'),
thumbnailUrl: expect.it('to be a string'),
url: expect.it('to be a string'),
};
export const attachmentImage = {
...attachmentCommons,
mediaType: expect.it('to equal', 'image'),
imageSizes: expect.it('to have keys satisfying', 'to be one of', ['o', 't', 't2'])
.and('to have values exhaustively satisfying', {
w: expect.it('to be a number'),
h: expect.it('to be a number'),
url: expect.it('to be a string'),
}),
};
export const attachmentAudio = {
...attachmentCommons,
mediaType: expect.it('to equal', 'audio'),
artist: expect.it('to be a string'),
title: expect.it('to be a string'),
imageSizes: expect.it('to be empty'),
};
export const attachmentGeneral = {
...attachmentCommons,
mediaType: expect.it('to equal', 'general'),
imageSizes: expect.it('to be empty'),
updatedAt: expect.it('to satisfy', timeStampString),
createdBy: expect.it('to satisfy', UUID),
mediaType: expect.it('to be one of', ['image', 'audio', 'general']),
fileName: expect.it('to be a string'),
fileSize: expect.it('to be a string').and('to match', /^\d+$/),
imageSizes: expect.it('to be an object'),
thumbnailUrl: expect.it('to be a string'),
url: expect.it('to be a string'),
};
export const attachmentImage = {
...attachmentCommons,
mediaType: expect.it('to equal', 'image'),
imageSizes: expect.it('to have keys satisfying', 'to be one of', ['o', 't', 't2'])
.and('to have values exhaustively satisfying', {
w: expect.it('to be a number'),
h: expect.it('to be a number'),
url: expect.it('to be a string'),
}),
};
export const attachmentAudio = {
...attachmentCommons,
mediaType: expect.it('to equal', 'audio'),
artist: expect.it('to be a string'),
title: expect.it('to be a string'),
imageSizes: expect.it('to be empty'),
};
export const attachmentGeneral = {
...attachmentCommons,
mediaType: expect.it('to equal', 'general'),
export const userSubscriptionsResponse = {
subscribers: expect.it('to be an array').and('to be empty').or('to have items satisfying', userOrGroup),
subscriptions: expect.it('to be an array').and('to be empty').or('to have items satisfying', {
id: expect.it('to satisfy', UUID),
name: expect.it('to be one of', ['Posts', 'Comments', 'Likes']),
user: expect.it('to satisfy', UUID),
}),
};
export const userSubscribersResponse = { subscribers: expect.it('to be an array').and('to be empty').or('to have items satisfying', user) };
export const appTokenInfo = {
id: expect.it('to satisfy', UUID),
title: expect.it('to be a string'),
issue: expect.it('to be a number'),
createdAt: expect.it('to satisfy', iso8601TimeString),
updatedAt: expect.it('to satisfy', iso8601TimeString),
scopes: expect.it('to be an array').and('to be empty').or('to have items satisfying', 'to be a string'),
restrictions: expect.it('to exhaustively satisfy', {
netmasks: expect.it('to be an array').and('to be empty').or('to have items satisfying', 'to be a string'),
origins: expect.it('to be an array').and('to be empty').or('to have items satisfying', 'to be a string'),
}),
lastUsedAt: expect.it('to be null').or('to satisfy', iso8601TimeString),
lastIP: expect.it('to be null').or('to be a string'),
lastUserAgent: expect.it('to be null').or('to be a string'),
};
export const serverInfoResponse = {
version: expect.it('to be a string'),
externalAuthProviders: expect.it('to be an array').and('to be empty').or('to have items satisfying', 'to be a string'),
};
return expect(obj, 'to exhaustively satisfy', {
...commentBasic,
createdBy: createdByExpectation,
});
};
const attachmentCommons = {
id: expect.it('to satisfy', UUID),
createdAt: expect.it('to satisfy', timeStampString),
updatedAt: expect.it('to satisfy', timeStampString),
createdBy: expect.it('to satisfy', UUID),
mediaType: expect.it('to be one of', ['image', 'audio', 'general']),
fileName: expect.it('to be a string'),
fileSize: expect.it('to be a string').and('to match', /^\d+$/),
imageSizes: expect.it('to be an object'),
thumbnailUrl: expect.it('to be a string'),
url: expect.it('to be a string'),
};
export const attachmentImage = {
...attachmentCommons,
mediaType: expect.it('to equal', 'image'),
imageSizes: expect.it('to have keys satisfying', 'to be one of', ['o', 't', 't2'])
.and('to have values exhaustively satisfying', {
w: expect.it('to be a number'),
h: expect.it('to be a number'),
url: expect.it('to be a string'),
}),
};
export const attachmentAudio = {
...attachmentCommons,
id: expect.it('to be a number'),
secure_id: expect.it('to satisfy', schema.UUID),
author: expect.it('to satisfy', schema.UUID),
message: expect.it('to be a string'),
lang: expect.it('to be a string'),
single_use: expect.it('to be a boolean'),
recommendations: expect.it('to satisfy', {
users: expect.it('to be an array').and('to be empty').or('to have items satisfying', (item) => {
expect(item, 'to be a string');
}),
groups: expect.it('to be an array').and('to be empty').or('to have items satisfying', (item) => {
expect(item, 'to be a string');
}),
}),
registrations_count: expect.it('to be a number'),
created_at: expect.it('when passed as parameter to', validator.isISO8601, 'to be', true),
}),
users: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.user),
groups: expect.it('to be an array').and('to be empty').or('to have items satisfying', schema.group)
});
};
const isGroup = obj && typeof obj === 'object' && obj.type === 'group';
return expect(obj, 'to exhaustively satisfy', isGroup ? group : user);
};
const postBasic = {
id: expect.it('to satisfy', UUID),
body: expect.it('to be a string'),
commentsDisabled: expect.it('to satisfy', boolString),
createdAt: expect.it('to satisfy', timeStampString),
updatedAt: expect.it('to satisfy', timeStampString),
createdBy: expect.it('to satisfy', UUID),
postedTo: expect.it('to be an array').and('to be empty').or('to have items satisfying', UUID),
attachments: expect.it('to be an array').and('to be empty').or('to have items satisfying', UUID),
comments: expect.it('to be an array').and('to be empty').or('to have items satisfying', UUID),
likes: expect.it('to be an array').and('to be empty').or('to have items satisfying', UUID),
omittedComments: expect.it('to be a number'),
omittedLikes: expect.it('to be a number'),
commentLikes: expect.it('to be a number'),
ownCommentLikes: expect.it('to be a number'),
omittedCommentLikes: expect.it('to be a number'),
omittedOwnCommentLikes: expect.it('to be a number'),
};
export const post = (obj) => {
const tpl = { ...postBasic };
if (obj && typeof obj === 'object' && ('isHidden' in obj)) {
tpl.isHidden = expect.it('to be', true);
}
if (obj && typeof obj === 'object' && ('isSaved' in obj)) {
tpl.isSaved = expect.it('to be', true);