summaryrefslogtreecommitdiff
path: root/src/services/chart/charts/classes/test.ts
blob: ea64040f3e5b2dea99405e8f8a03110d4260b565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import autobind from 'autobind-decorator';
import Chart, { Obj, DeepPartial } from '../../core';
import { SchemaType } from '../../../../misc/schema';
import { name, schema } from '../schemas/test';

type TestLog = SchemaType<typeof schema>;

export default class TestChart extends Chart<TestLog> {
	public total = 0; // publicにするのはテストのため

	constructor() {
		super(name, schema);
	}

	@autobind
	protected genNewLog(latest: TestLog): DeepPartial<TestLog> {
		return {
			foo: {
				total: latest.foo.total,
			},
		};
	}

	@autobind
	protected async fetchActual(): Promise<DeepPartial<TestLog>> {
		return {
			foo: {
				total: this.total,
			},
		};
	}

	@autobind
	public async increment() {
		const update: Obj = {};

		update.total = 1;
		update.inc = 1;
		this.total++;

		await this.inc({
			foo: update
		});
	}

	@autobind
	public async decrement() {
		const update: Obj = {};

		update.total = -1;
		update.dec = 1;
		this.total--;

		await this.inc({
			foo: update
		});
	}
}