How to use the couchbase.Cluster.prototype function in couchbase

To help you get started, we’ve selected a few couchbase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github puzzle-js / puzzle-warden / test / couchbase.spec.ts View on Github external
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);
  });
github puzzle-js / puzzle-warden / test / couchbase.spec.ts View on Github external
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);
  });