From 02cc67a2e56e908edb3a8adf1a9830602cd83f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Mestres?= Date: Tue, 24 Oct 2023 11:10:39 +0200 Subject: [PATCH] chore: remove counter service & related code --- app/services/counter.ts | 52 ----------------------------- app/templates/app/generator.hbs | 8 ----- tests/unit/services/counter-test.ts | 41 ----------------------- 3 files changed, 101 deletions(-) delete mode 100644 app/services/counter.ts delete mode 100644 tests/unit/services/counter-test.ts diff --git a/app/services/counter.ts b/app/services/counter.ts deleted file mode 100644 index 3aca12b..0000000 --- a/app/services/counter.ts +++ /dev/null @@ -1,52 +0,0 @@ -import Service from '@ember/service'; -import { tracked } from '@glimmer/tracking'; - -import config from 'text2stl/config/environment'; -const { - APP: { countApi }, -} = config; - -export default class CounterService extends Service { - @tracked - _counter?: number = undefined; - - // For test purpose only - _initPromise?: Promise; - - get counter(): number { - if (this._counter === undefined) { - // eslint-disable-next-line ember/no-side-effects - this._initPromise = this.initCounter(); - } - - return this._counter ?? 0; - } - - // For easy mock - fetch(input: RequestInfo, init?: RequestInit | undefined): Promise { - return fetch(input, init); - } - - private async initCounter(): Promise { - const res = await this.fetch( - `https://api.countapi.xyz/get/${countApi.namespace}/${countApi.key}`, - ); - const data = await res.json(); - this._counter = data.value; - } - - async updateCounter() { - const res = await this.fetch( - `https://api.countapi.xyz/hit/${countApi.namespace}/${countApi.key}`, - ); - const data = await res.json(); - this._counter = data.value; - } -} - -// DO NOT DELETE: this is how TypeScript knows how to look up your services. -declare module '@ember/service' { - interface Registry { - counter: CounterService; - } -} diff --git a/app/templates/app/generator.hbs b/app/templates/app/generator.hbs index 8159c14..c4027f9 100644 --- a/app/templates/app/generator.hbs +++ b/app/templates/app/generator.hbs @@ -42,14 +42,6 @@ >
- {{!-- {{#if this.counter}} - -
- {{t 'stl_counter' count=this.counter}} -
-
- {{/if}} --}} - fetchReturn, - }; - } as unknown as typeof fetch; - - expectedUrl = 'https://api.countapi.xyz/get/text2stl/test_stl'; - fetchReturn = { value: 123 }; - - assert.strictEqual(service.counter, 0, 'first get for counter return 0'); - - await service._initPromise; - assert.strictEqual(service.counter, 123, 'counter is now conform to counterApi response'); - - expectedUrl = 'https://api.countapi.xyz/hit/text2stl/test_stl'; - fetchReturn = { value: 1256 }; - await service.updateCounter(); - - assert.strictEqual(service.counter, 1256, 'counter is conform to counterApi response'); - - assert.ok(service); - }); -});