-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js.map
1 lines (1 loc) · 8.44 KB
/
index.test.js.map
1
{"version":3,"sources":["src/index.test.js"],"names":["mockData","describe","afterEach","reset","restore","it","expect","toBeTruthy","getOnce","body","headers","myCache","get","fetch","method","credentials","then","response","json","article","title","toBe","toEqual","done","Promise","all","results","length","calls","status","ok","Error","statusText","catch","reason","message","data","toBeNull","clear","Object","keys","cache"],"mappings":";;AAAA;;;;AAEA;;AACA;;;;;;AAEA,IAAMA,WAAW,CACf;AACE,QAAK,OADP;AAEE,WAAS;AAFX,CADe,EAKf;AACE,QAAK,OADP;AAEE,WAAS;AAFX,CALe,CAAjB;;AAWAC,SAAS,cAAT,EAAyB,YAAM;;AAE7BC,YAAU,YAAM;AACd,wBAAUC,KAAV;AACA,wBAAUC,OAAV;AACD,GAHD;;AAKAC,KAAG,qBAAH,EAA0B,YAAM;AAC9BC,WAAO,qBAAP,EAA0BC,UAA1B;AACD,GAFD;;AAIAF,KAAG,0DAAH,EAA+D,YAAM;AACnE,wBAAUG,OAAV,CAAkB,qBAAlB,EAAyC,EAAEC,MAAMT,SAAS,CAAT,CAAR,EAAqBU,SAAS,EAAE,gBAAgB,kBAAlB,EAA9B,EAAzC;;AAEA,QAAMC,UAAU,qBAAhB;;AAEA,WAAOA,QAAQC,GAAR,CAAY,eAAZ,EAA6B,YAAY;AAC9C,aAAOC,6BAA6B;AAClCC,gBAAQ,KAD0B;AAElCJ,iBAAS;AACP,0BAAgB;AADT,SAFyB;AAKlCK,qBAAa;AALqB,OAA7B,EAOJC,IAPI,CAOC;AAAA,eAAYC,SAASC,IAAT,EAAZ;AAAA,OAPD,CAAP;AAQD,KATM,EAUJF,IAVI,CAUC,UAACG,OAAD,EAAa;AACjBb,aAAOa,QAAQC,KAAf,EAAsBC,IAAtB,CAA2B,oBAA3B;AACAV,cAAQC,GAAR,CAAY,eAAZ,EAA6BI,IAA7B,CAAkC,UAACG,OAAD,EAAa;AAC7Cb,eAAO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Q8B,KAApB,EAA2Bd,MAAlC,EAA0CN,IAA1C,CAA+C,CAA/C;AACD,KAbI,CAAP;AAeD,GArBD;;AAuBAhB,KAAG,gCAAH,EAAqC,YAAM;;AAEzC,wBAAUG,OAAV,CAAkB,qBAAlB,EAAyC,EAAEC,MAAMT,SAAS,CAAT,CAAR,EAAqBU,SAAS,EAAE,gBAAgB,kBAAlB,EAA9B,EAAzC;;AAEA,QAAMC,UAAU,qBAAhB;;AAEA,WAAOA,QAAQC,GAAR,CAAY,eAAZ,EAA6B,YAAY;AAC9C,aAAOC,6BAA6B;AAClCC,gBAAQ,KAD0B;AAElCJ,iBAAS;AACP,0BAAgB;AADT,SAFyB;AAKlCK,qBAAa;AALqB,OAA7B,EAOJC,IAPI,CAOC;AAAA,eAAYC,SAASC,IAAT,EAAZ;AAAA,OAPD,CAAP;AAQD,KATM,EAUJF,IAVI,CAUC,UAACG,OAAD,EAAa;AACjBR,cAAQ2B,KAAR,CAAc,eAAd;AACAhC,aAAOiC,OAAOC,IAAP,CAAY7B,QAAQ8B,KAApB,EAA2Bd,MAAlC,EAA0CN,IAA1C,CAA+C,CAA/C;AACD,KAbI,CAAP;AAeD,GArBD;AAuBD,CAtJD","file":"index.test.js","sourcesContent":["import ClientCache from './index'\n\nimport 'isomorphic-fetch'\nimport fetchMock from 'fetch-mock'\n\nconst mockData = [\n {\n \"id\":\"12345\",\n \"title\": \"test article title\"\n },\n {\n \"id\":\"67890\",\n \"title\": \"test article title 2\"\n },\n]\n\ndescribe('client cache', () => {\n\n afterEach(() => {\n fetchMock.reset()\n fetchMock.restore()\n })\n\n it('can be instantiated', () => {\n expect(new ClientCache()).toBeTruthy()\n })\n\n it('give me the data back and cache it when not in the cache', () => {\n fetchMock.getOnce('/api/articles/12345', { body: mockData[0], headers: { 'content-type': 'application/json' } })\n\n const myCache = new ClientCache();\n\n return myCache.get('article-12345', function () {\n return fetch(`/api/articles/12345`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => response.json())\n })\n .then((article) => {\n expect(article.title).toBe('test article title')\n myCache.get('article-12345').then((article) => {\n expect(article).toEqual(mockData[0])\n })\n })\n })\n\n it('will resolve all the outstandng promises as they come in', (done) => {\n fetchMock.getOnce('/api/articles/12345', { body: mockData[0], headers: { 'content-type': 'application/json' } })\n\n const myCache = new ClientCache();\n\n Promise.all([\n myCache.get('article-12345', function () {\n return fetch(`/api/articles/12345`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => response.json())\n }),\n myCache.get('article-12345', function () {\n return fetch(`/api/articles/12345`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => response.json())\n })\n ])\n .then((results) => {\n expect(results.length).toBe(2)\n expect(fetchMock.calls('/api/articles/12345')[0].length).toBe(2)\n done()\n })\n })\n\n it('will give you the error if it happens when executing the request', () => {\n fetchMock.getOnce('/api/articles/67890', { status: 500, headers: { 'content-type': 'application/json' } })\n\n const myCache = new ClientCache();\n\n return myCache.get('article-67890', function () {\n return fetch(`/api/articles/67890`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => {\n if (response.ok) return response.json()\n throw new Error(response.statusText)\n })\n })\n .catch((reason) => {\n expect(reason.message).toBe('Internal Server Error')\n })\n })\n\n\n it('will give you null if you do a normal get with no request function and it does not exist', () => {\n\n const myCache = new ClientCache();\n\n return myCache\n .get('asdfasdfasdf')\n .then((data) => {\n expect(data).toBeNull()\n })\n\n })\n\n it('let you clear the cache', () => {\n\n fetchMock.getOnce('/api/articles/12345', { body: mockData[0], headers: { 'content-type': 'application/json' } })\n\n const myCache = new ClientCache();\n\n return myCache.get('article-12345', function () {\n return fetch(`/api/articles/12345`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => response.json())\n })\n .then((article) => {\n myCache.clear()\n expect(Object.keys(myCache.cache).length).toBe(0)\n })\n\n })\n\n it('let you clear the cache by key', () => {\n\n fetchMock.getOnce('/api/articles/12345', { body: mockData[0], headers: { 'content-type': 'application/json' } })\n\n const myCache = new ClientCache();\n\n return myCache.get('article-12345', function () {\n return fetch(`/api/articles/12345`, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json'\n },\n credentials: 'same-origin'\n })\n .then(response => response.json())\n })\n .then((article) => {\n myCache.clear('article-12345')\n expect(Object.keys(myCache.cache).length).toBe(0)\n })\n\n })\n\n})\n"]}