Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const UUID = require("uuidjs")
// Generate UUID string
console.log(UUID.generate())
// Create UUID objects and get string representations
console.log(UUID.genV4().toString())
console.log(UUID.genV1().hexNoDelim)
console.log(UUID.parse("84d9ca79-4d66-4373-91a0-a12d673e71be").urn)
// Get UUID internal field values
console.log(UUID.genV4().hexFields.node)
console.log(UUID.genV1().intFields.timeLow)
console.log(UUID.genV4().bitFields[2])
UUID.genV1()
it('calls the `onFieldsLoaded` function when fields are loaded', () => {
const richProfileRepository = new RichProfileRepository(resolve(graph.BackendClient));
const userId = UUID.genV4().hexString;
const params = {onFieldsLoaded: () => {}, richProfileRepository, user: () => ({email: () => {}, id: userId})};
const richProfile = {
fields: [
{type: 'field1', value: 'value1'},
{type: 'field2', value: 'value2'},
],
};
spyOn(richProfileRepository, 'getUserRichProfile').and.returnValue(Promise.resolve(richProfile));
spyOn(params, 'onFieldsLoaded');
return instantiateComponent('enriched-fields', params).then(() => {
expect(params.onFieldsLoaded).toHaveBeenCalledWith(richProfile.fields);
});
});
});
describe('PreferenceNotificationRepository', () => {
const user = {id: UUID.genV4().hexString};
const userObservable = () => user;
beforeEach(() => {
spyOn(amplify, 'store').and.callFake(() => {});
});
it('subscribes to preference change events', () => {
spyOn(amplify, 'subscribe').and.callFake(() => {});
const preferenceNotificationRepository = new PreferenceNotificationRepository(userObservable);
expect(amplify.subscribe).toHaveBeenCalledTimes(3);
expect(preferenceNotificationRepository.notifications().length).toBe(0);
});
it('adds new notification when read receipt settings are changed', () => {
describe('ReceiptsMiddleware', () => {
const selfId = UUID.genV4();
let readReceiptMiddleware;
const eventService = {loadEvents: noop, replaceEvent: noop};
const userRepository = {
self: () => ({
id: selfId,
}),
};
beforeEach(() => {
readReceiptMiddleware = new ReceiptsMiddleware(eventService, userRepository);
});
describe('processEvent', () => {
it('ignores read receipt for which original message is not found', () => {
const event = createConfirmationEvent(3);
function createConfirmationEvent(status, moreMessageIds = []) {
return {
conversation: UUID.genV4(),
data: {
message_id: UUID.genV4(),
more_message_ids: moreMessageIds,
status,
},
from: UUID.genV4(),
time: '12-12-12',
type: ClientEvent.CONVERSATION.CONFIRMATION,
};
}
function createConfirmationEvent(status, moreMessageIds = []) {
return {
conversation: UUID.genV4(),
data: {
message_id: UUID.genV4(),
more_message_ids: moreMessageIds,
status,
},
from: UUID.genV4(),
time: '12-12-12',
type: ClientEvent.CONVERSATION.CONFIRMATION,
};
}
selfId: () => UUID.genV4().hexString,
shouldShowAvatar: true,
export const createRandomUuid = (): string => UUID.genV4().hexString;
constructor(params) {
this.dataUieNameInfoText = `status-info-toggle-${params.dataUieName}`;
this.dataUieNameLabelText = `do-toggle-${params.dataUieName}`;
this.info = params.info;
this.inputId = UUID.genV4();
this.isChecked = params.isChecked;
this.isDisabled = params.isDisabled;
this.name = params.name;
}
}
bench('UuidJs v4 Canonical', function() {
UuidJs.genV4().toString();
});
});