mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 15:36:25 +00:00
refactor(github): Remove unused method from ApiCache
class (#24117)
This commit is contained in:
parent
aa111993c3
commit
b71e4b0a81
2 changed files with 0 additions and 24 deletions
|
@ -4,19 +4,10 @@ import { ApiCache } from './api-cache';
|
||||||
describe('modules/platform/github/api-cache', () => {
|
describe('modules/platform/github/api-cache', () => {
|
||||||
const now = DateTime.fromISO('2000-01-01T00:00:00.000+00:00');
|
const now = DateTime.fromISO('2000-01-01T00:00:00.000+00:00');
|
||||||
const t1 = now.plus({ years: 1 }).toISO()!;
|
const t1 = now.plus({ years: 1 }).toISO()!;
|
||||||
const t1_http = now.plus({ years: 1 }).toHTTP();
|
|
||||||
|
|
||||||
const t2 = now.plus({ years: 2 }).toISO()!;
|
const t2 = now.plus({ years: 2 }).toISO()!;
|
||||||
const t2_http = now.plus({ years: 2 }).toHTTP();
|
|
||||||
|
|
||||||
const t3 = now.plus({ years: 3 }).toISO()!;
|
const t3 = now.plus({ years: 3 }).toISO()!;
|
||||||
const t3_http = now.plus({ years: 3 }).toHTTP();
|
|
||||||
|
|
||||||
const t4 = now.plus({ years: 4 }).toISO()!;
|
const t4 = now.plus({ years: 4 }).toISO()!;
|
||||||
const t4_http = now.plus({ years: 4 }).toHTTP();
|
|
||||||
|
|
||||||
const t5 = now.plus({ years: 5 }).toISO()!;
|
const t5 = now.plus({ years: 5 }).toISO()!;
|
||||||
const t5_http = now.plus({ years: 5 }).toHTTP();
|
|
||||||
|
|
||||||
it('stores and retrieves items', () => {
|
it('stores and retrieves items', () => {
|
||||||
const item1 = { number: 1, updated_at: t1 };
|
const item1 = { number: 1, updated_at: t1 };
|
||||||
|
@ -31,7 +22,6 @@ describe('modules/platform/github/api-cache', () => {
|
||||||
|
|
||||||
apiCache.updateItem(item2);
|
apiCache.updateItem(item2);
|
||||||
expect(apiCache.getItem(2)).toBe(item2);
|
expect(apiCache.getItem(2)).toBe(item2);
|
||||||
expect(apiCache.lastModified).toBe(t1_http); // Not `t2`, see jsdoc for `setItem`
|
|
||||||
expect(apiCache.getItems()).toEqual([item1, item2]);
|
expect(apiCache.getItems()).toEqual([item1, item2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -103,20 +93,17 @@ describe('modules/platform/github/api-cache', () => {
|
||||||
describe('reconcile', () => {
|
describe('reconcile', () => {
|
||||||
it('appends new items', () => {
|
it('appends new items', () => {
|
||||||
const apiCache = new ApiCache({ items: {} });
|
const apiCache = new ApiCache({ items: {} });
|
||||||
expect(apiCache.lastModified).toBeNull();
|
|
||||||
|
|
||||||
const res1 = apiCache.reconcile([
|
const res1 = apiCache.reconcile([
|
||||||
{ number: 2, updated_at: t2 },
|
{ number: 2, updated_at: t2 },
|
||||||
{ number: 1, updated_at: t1 },
|
{ number: 1, updated_at: t1 },
|
||||||
]);
|
]);
|
||||||
expect(apiCache.lastModified).toBe(t2_http);
|
|
||||||
expect(res1).toBeTrue();
|
expect(res1).toBeTrue();
|
||||||
|
|
||||||
const res2 = apiCache.reconcile([
|
const res2 = apiCache.reconcile([
|
||||||
{ number: 4, updated_at: t4 },
|
{ number: 4, updated_at: t4 },
|
||||||
{ number: 3, updated_at: t3 },
|
{ number: 3, updated_at: t3 },
|
||||||
]);
|
]);
|
||||||
expect(apiCache.lastModified).toBe(t4_http);
|
|
||||||
expect(res2).toBeTrue();
|
expect(res2).toBeTrue();
|
||||||
|
|
||||||
expect(apiCache.getItems()).toEqual([
|
expect(apiCache.getItems()).toEqual([
|
||||||
|
@ -148,7 +135,6 @@ describe('modules/platform/github/api-cache', () => {
|
||||||
{ number: 2, updated_at: t4 },
|
{ number: 2, updated_at: t4 },
|
||||||
{ number: 3, updated_at: t3 },
|
{ number: 3, updated_at: t3 },
|
||||||
]);
|
]);
|
||||||
expect(apiCache.lastModified).toBe(t5_http);
|
|
||||||
expect(needNextPage).toBeFalse();
|
expect(needNextPage).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -175,7 +161,6 @@ describe('modules/platform/github/api-cache', () => {
|
||||||
{ number: 4, updated_at: t4 },
|
{ number: 4, updated_at: t4 },
|
||||||
{ number: 5, updated_at: t5 },
|
{ number: 5, updated_at: t5 },
|
||||||
]);
|
]);
|
||||||
expect(apiCache.lastModified).toBe(t5_http);
|
|
||||||
expect(res1).toBeTrue();
|
expect(res1).toBeTrue();
|
||||||
expect(res2).toBeTrue();
|
expect(res2).toBeTrue();
|
||||||
});
|
});
|
||||||
|
@ -201,7 +186,6 @@ describe('modules/platform/github/api-cache', () => {
|
||||||
{ number: 2, updated_at: t2 },
|
{ number: 2, updated_at: t2 },
|
||||||
{ number: 3, updated_at: t3 },
|
{ number: 3, updated_at: t3 },
|
||||||
]);
|
]);
|
||||||
expect(apiCache.lastModified).toBe(t3_http);
|
|
||||||
expect(needNextPage).toBeFalse();
|
expect(needNextPage).toBeFalse();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,14 +5,6 @@ import type { ApiPageCache, ApiPageItem } from './types';
|
||||||
export class ApiCache<T extends ApiPageItem> {
|
export class ApiCache<T extends ApiPageItem> {
|
||||||
constructor(private cache: ApiPageCache<T>) {}
|
constructor(private cache: ApiPageCache<T>) {}
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns Date formatted to use in HTTP headers
|
|
||||||
*/
|
|
||||||
get lastModified(): string | null {
|
|
||||||
const { lastModified } = this.cache;
|
|
||||||
return lastModified ? DateTime.fromISO(lastModified).toHTTP() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
getItems(): T[] {
|
getItems(): T[] {
|
||||||
const items = Object.values(this.cache.items);
|
const items = Object.values(this.cache.items);
|
||||||
return items;
|
return items;
|
||||||
|
|
Loading…
Reference in a new issue