Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async _setupChannel(event: SetupChannelAction) {
try {
const hasChannel = await this._client
.branchInfo(event.channel)
.pipe(map(e => e.exists))
.toPromise();
if (!hasChannel) {
console.log(
`[SetupChannelModule2] Setting up new channel ${
event.channel
}`
);
// TODO: Rework so that other modules can be used like webhooks.
const simulation = nodeSimulationForBranch(
this._user,
this._client,
event.channel
);
try {
await simulation.init();
if (event.botOrMod) {
console.log(`[SetupChannelModule2] Creating new bot`);
const botId = await simulation.helper.createBot(
undefined,
isBot(event.botOrMod)
? event.botOrMod.tags
: event.botOrMod
);
console.log(
expect.assertions(2);
await simulation.helper.transaction(
setupChannel('newChannel', {
onCreate: '@setTag(this, "created", true)',
})
);
await waitAsync();
const channelInfo = await serverClient
.branchInfo('newChannel')
.toPromise();
expect(channelInfo.exists).toBe(true);
const newChannelSim = nodeSimulationForBranch(
processingUser,
processingClient,
'newChannel'
);
await newChannelSim.init();
const { result } = await newChannelSim.helper.search(
`getBot("created", true)`
);
expect(result).toEqual(
createBot(result.id, {
onCreate: '@setTag(this, "created", true)',
created: true,
})
);
});
]);
const server = new CausalRepoServer(
fixedConnectionServer,
store,
stageStore
);
server.init();
serverClient = new CausalRepoClient(serverBridge.clientConnection);
processingClient = new CausalRepoClient(
processingBridge.clientConnection
);
subject = new SetupChannelModule2(serverUser, serverClient);
simulation = nodeSimulationForBranch(user, serverClient, 'id');
await simulation.init();
sub = await subject.setup(simulation);
});
[USERNAME_CLAIM]: 'username',
[DEVICE_ID_CLAIM]: 'deviceId',
[SESSION_ID_CLAIM]: 'sessionId',
},
roles: [],
};
serverDevice = {
claims: {
[USERNAME_CLAIM]: 'server',
[DEVICE_ID_CLAIM]: 'deviceId',
[SESSION_ID_CLAIM]: 'sessionId',
},
roles: [SERVER_ROLE],
};
simulation = nodeSimulationWithConfig(user, 'test', config);
await simulation.init();
subject = new WebhooksModule2();
sub = await subject.setup(simulation);
});
(id: string) =>
nodeSimulationForBranch(
this._user,
this._client,
id,
{
readOnly: true,
}
),
this._client
server.whileCausalTreeLoaded((tree, info) => {
const simulation = new NodeSimulation(
serverUser,
info.id,
{
isBuilder: false,
isPlayer: false,
},
tree
);
return [simulation];
}),
];
lib => new VM2Sandbox(lib)
);