Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should connect couchbase bucket without authorization', async () => {
// Arrange
const host = faker.random.word();
const bucketName = faker.random.word();
const couchbase = new CouchbaseCache({host, bucketName});
const bucket = createBucket();
const spy = sandbox.stub(Cluster.prototype, 'openBucket').returns(bucket as any);
// Act
await couchbase.connect();
// Assert
expect(spy.calledWithExactly(bucketName)).to.eq(true);
});
it('should return cached content if it is valid', async () => {
// Arrange
const host = faker.random.word();
const bucketName = faker.random.word();
const username = faker.random.word();
const password = faker.random.word();
const key = faker.random.word();
const couchbase = new CouchbaseCache({host, bucketName, username, password});
const bucket = createBucket();
const data = faker.random.word();
sandbox.stub(Cluster.prototype, 'openBucket').returns(bucket as any);
const getSpy = sandbox.stub(bucket, 'get')
.callsArgWith(1, null, {
value: data
});
// Act
await couchbase.connect();
const item = await couchbase.get(key);
// Assert
expect(getSpy.calledWith(key, sinon.match.func)).to.eq(true);
expect(item).to.eq(data);
});