var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import chaiAsPromised from 'chai-as-promised';
import sinon from 'sinon';
import chai, { expect } from 'chai';
import { DidIonResolver } from '../../src/did/did-ion-resolver.js';
import { DidResolver } from '../../src/did/did-resolver.js';
// extends chai to test promises
chai.use(chaiAsPromised);
describe('DidResolver', () => {
    if (process.env.TESTSOFF === 'true') {
        return;
    }
    it('should cache the resolution result and use the cached result when available', () => __awaiter(void 0, void 0, void 0, function* () {
        const did = 'did:ion:unusedDid';
        const didIonResolver = new DidIonResolver('unusedResolutionEndpoint');
        const didResolver = new DidResolver([didIonResolver]);
        const mockResolution = {
            didDocument: 'any',
            didDocumentMetadata: 'any',
            didResolutionMetadata: 'any'
        };
        const ionDidResolveSpy = sinon.stub(didIonResolver, 'resolve').resolves(mockResolution);
        const cacheGetSpy = sinon.spy(didResolver['cache'], 'get');
        // calling resolve twice
        const resolutionResult1 = yield didResolver.resolve(did);
        expect(resolutionResult1).to.equal(mockResolution);
        const resolutionResult2 = yield didResolver.resolve(did);
        expect(resolutionResult2).to.equal(mockResolution);
        sinon.assert.calledTwice(cacheGetSpy); // should try to fetch from cache both times
        sinon.assert.calledOnce(ionDidResolveSpy); // should only resolve using ION resolver once (the first time)
    }));
});
//# sourceMappingURL=did-resolver.spec.js.map