fix: re-revert the API decoupling (#41263)
* fix(api): decouple api from curriculum This reverts commit8f0e441644
and introduces the implementations from #40703. * fix(gitpod): add curriculum build to GitPod This reverts commit706d70f58d
and introduces implementations from #41234. * docs: update DevOps manual for api change (#41259) Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
GitHub
parent
31bdea63a2
commit
b5f4754e2a
68
api-server/src/server/utils/in-memory-cache.test.js
Normal file
68
api-server/src/server/utils/in-memory-cache.test.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/* global describe beforeEach expect it */
|
||||
import inMemoryCache from './in-memory-cache';
|
||||
import sinon from 'sinon';
|
||||
|
||||
describe('InMemoryCache', () => {
|
||||
let reportErrorStub;
|
||||
const theAnswer = 42;
|
||||
const before = 'before';
|
||||
const after = 'after';
|
||||
const emptyCacheValue = null;
|
||||
|
||||
beforeEach(() => {
|
||||
reportErrorStub = sinon.spy();
|
||||
});
|
||||
|
||||
it('throws if no report function is passed as a second argument', () => {
|
||||
expect(() => inMemoryCache(null)).toThrowError(
|
||||
'No reportError function specified for this in-memory-cache'
|
||||
);
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
it('returns an initial value', () => {
|
||||
const cache = inMemoryCache(theAnswer, reportErrorStub);
|
||||
expect(cache.get()).toBe(theAnswer);
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
it('updates the cached value', () => {
|
||||
const cache = inMemoryCache(before, reportErrorStub);
|
||||
cache.update(() => after);
|
||||
expect(cache.get()).toBe(after);
|
||||
});
|
||||
|
||||
it('can handle promises correctly', done => {
|
||||
const cache = inMemoryCache(before, reportErrorStub);
|
||||
const promisedUpdate = () => new Promise(resolve => resolve(after));
|
||||
cache.update(promisedUpdate).then(() => {
|
||||
expect(cache.get()).toBe(after);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('reports errors thrown from the update function', () => {
|
||||
const reportErrorStub = sinon.spy();
|
||||
const cache = inMemoryCache(before, reportErrorStub);
|
||||
|
||||
const updateError = new Error('An update error');
|
||||
const updateThatThrows = () => {
|
||||
throw updateError;
|
||||
};
|
||||
|
||||
cache.update(updateThatThrows);
|
||||
expect(reportErrorStub.calledWith(updateError)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('clear', () => {
|
||||
it('clears the cache', () => {
|
||||
expect.assertions(2);
|
||||
const cache = inMemoryCache(theAnswer, reportErrorStub);
|
||||
expect(cache.get()).toBe(theAnswer);
|
||||
cache.clear();
|
||||
expect(cache.get()).toBe(emptyCacheValue);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user