Files
raucao 4f3c4334bd Use only normal API keys for OpenRouter spend
OpenRouter now rejects management keys from the browser on both
/api/v1/keys and /api/v1/analytics/query, so the management-key flow can
no longer work in the extension. Read the configured key's own usage from
GET /api/v1/key instead, which returns UTC daily, weekly, and monthly
buckets and works from the browser.

Drop the key-type selection, key listing/selection, pagination, and the
management/analytics endpoints. Validate the key against /key before
persisting, and write a fresh record so legacy keyType/keyIds fields are
dropped. Keep the browser-block hint for anyone still storing a
management key.
2026-11-16 22:16:35 +04:00

214 lines
6.4 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, triggerEvent } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import List from 'dashtab/components/settings/integrations/add-list';
class FakeSitesService {
@tracked all = [];
}
class FakeNotificationsService {
stateFor() {
return { error: null, errorType: null };
}
}
class FakeBitcoinService {
@tracked enabled = false;
@tracked interval = 30000;
@tracked provider = 'coingecko';
}
class FakeOpenRouterService {
@tracked enabled = false;
@tracked apiKey = null;
@tracked interval = 300000;
@tracked granularity = 'today';
async disable() {}
}
// The real calendar service loads asynchronously in its constructor and
// re-renders the list when it resolves. That can tear down a button between the
// click's element lookup and its event dispatch, which made the click test
// flake. A stub keeps the list stable for the whole test.
class FakeCalendarService {
instancesFor() {
return [];
}
}
class FakeModalService {
replaced = null;
open(descriptor) {
this.replaced = descriptor;
}
replace(descriptor) {
this.replaced = descriptor;
}
}
function register(owner, overrides = {}) {
owner.register('service:sites', overrides.sites ?? new FakeSitesService(), {
instantiate: false,
});
owner.register(
'service:notifications',
overrides.notifications ?? new FakeNotificationsService(),
{ instantiate: false }
);
owner.register(
'service:bitcoin',
overrides.bitcoin ?? new FakeBitcoinService(),
{ instantiate: false }
);
owner.register(
'service:openrouter',
overrides.openrouter ?? new FakeOpenRouterService(),
{ instantiate: false }
);
owner.register(
'service:calendar',
overrides.calendar ?? new FakeCalendarService(),
{ instantiate: false }
);
const modal = overrides.modal ?? new FakeModalService();
owner.register('service:modal', modal, { instantiate: false });
return { modal };
}
module(
'Integration | Component | settings/integrations/add-list',
function (hooks) {
setupRenderingTest(hooks);
test('it renders every available integration', async function (assert) {
register(this.owner);
await render(<template><List /></template>);
assert.dom().containsText('Discourse');
assert.dom().containsText('Notifications from your discussion forums');
assert.dom().containsText('Bitcoin Price Ticker');
assert.dom().containsText('Live BTC price');
assert.dom().containsText('Feedbin');
assert.dom().containsText('Unread count from your Feedbin RSS reader');
assert.dom().containsText('GitHub');
assert.dom().containsText('Unread notifications from GitHub');
assert.dom().containsText('Gitea');
assert
.dom()
.containsText('Unread notifications from your Gitea instances');
assert
.dom('[data-add="discourse"] img[src="/img/icons/discourse.svg"]')
.exists();
assert
.dom('[data-add="feedbin"] img[src="/img/icons/feedbin.png"]')
.exists();
assert
.dom('[data-add="github"] img[src="/img/icons/github-inverted.png"]')
.exists();
assert.dom('[data-add="github"]').doesNotHaveAttribute('disabled');
assert.dom('[data-add="gitea"] img[src="/img/icons/gitea.png"]').exists();
assert.dom('[data-add="gitea"]').doesNotHaveAttribute('disabled');
assert.dom().containsText('Home Assistant');
assert
.dom()
.containsText('Notifications from your Home Assistant instances');
assert
.dom(
'[data-add="homeassistant"] img[src="/img/icons/home-assistant.png"]'
)
.exists();
assert.dom('[data-add="homeassistant"]').doesNotHaveAttribute('disabled');
assert.dom().containsText('Custom Link');
assert.dom().containsText('Add any website as a quick link');
assert.dom('[data-add="custom"]').exists();
assert.dom('[data-add="custom"]').doesNotHaveAttribute('disabled');
});
test('it can be scoped to a subset of integration types', async function (assert) {
register(this.owner);
const props = { types: ['discourse', 'feedbin'] };
await render(<template><List @props={{props}} /></template>);
assert.dom('[data-add="discourse"]').exists();
assert.dom('[data-add="feedbin"]').exists();
assert.dom('[data-add="github"]').doesNotExist();
assert.dom('[data-add="homeassistant"]').doesNotExist();
assert.dom('[data-add="calendar-caldav"]').doesNotExist();
assert.dom('[data-add="custom"]').doesNotExist();
});
test('it sorts the available integrations by name', async function (assert) {
register(this.owner);
const props = {
types: ['discourse', 'github', 'gitea', 'feedbin', 'homeassistant'],
};
await render(<template><List @props={{props}} /></template>);
const ids = [...this.element.querySelectorAll('[data-add]')].map(
(el) => el.dataset.add
);
assert.deepEqual(ids, [
'discourse',
'feedbin',
'gitea',
'github',
'homeassistant',
]);
});
test('it sorts the generic Custom Link type last', async function (assert) {
register(this.owner);
const props = { types: ['custom', 'discourse', 'github'] };
await render(<template><List @props={{props}} /></template>);
const ids = [...this.element.querySelectorAll('[data-add]')].map(
(el) => el.dataset.add
);
assert.deepEqual(ids, ['discourse', 'github', 'custom']);
});
test('clicking an integration opens its add form', async function (assert) {
const { modal } = register(this.owner);
await render(<template><List /></template>);
const btn = this.element.querySelector('[data-add="discourse"]');
await triggerEvent(btn, 'click');
assert.ok(modal.replaced.component);
assert.strictEqual(modal.replaced.props.mode, 'add');
assert.strictEqual(modal.replaced.size, 'md');
});
test('hides an already connected single-instance integration', async function (assert) {
const bitcoin = new FakeBitcoinService();
bitcoin.enabled = true;
register(this.owner, { bitcoin });
await render(<template><List /></template>);
assert.dom('[data-add="bitcoin"]').doesNotExist();
assert.dom('[data-add="discourse"]').exists();
});
}
);