forked from Furumi/furumi-web
Add the share toggle and privacy dialog to the podcast page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
588ea4e99e
commit
74ad88d06e
6 files changed
+318
-2
No files matched your search
@@ -786,7 +786,7 @@ test('a mirrored Jam state never plays or saves an episode', async () => {
|
||||
// Podcasts store
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function podcastsStore(stores = {}) {
|
||||
function podcastsStore(stores = {}, overrides = {}) {
|
||||
const start = template.indexOf(" Alpine.store('podcasts', {");
|
||||
assert.ok(start >= 0);
|
||||
const open = template.indexOf('{', start);
|
||||
@@ -800,9 +800,14 @@ function podcastsStore(stores = {}) {
|
||||
podcastJamBlocked: 'jam blocked', podcastRequestFailed: 'request failed',
|
||||
},
|
||||
URLSearchParams, GUEST: false,
|
||||
fetch: async (url, init = {}) => { calls.push({url, init}); return {ok: true, json: async () => ({})}; },
|
||||
fetch: async (url, init = {}) => {
|
||||
calls.push({url, init});
|
||||
if (overrides.respond) return overrides.respond(url, init);
|
||||
return {ok: true, json: async () => ({})};
|
||||
},
|
||||
Alpine: {store: name => stores[name]},
|
||||
});
|
||||
Object.assign(context.T, overrides.T || {});
|
||||
vm.runInContext('this.store = ' + template.slice(open, end + 6) + ';', context);
|
||||
return {store: context.store, calls};
|
||||
}
|
||||
@@ -839,6 +844,87 @@ test('the podcasts store formats episodes and builds list queries', () => {
|
||||
assert.equal(store._episodeQuery(0), 'limit=50&offset=0');
|
||||
});
|
||||
|
||||
test('sharing a feed URL that looks private asks first and sends back exactly the shown URLs', async () => {
|
||||
const secret = 'https://members.example/feed.xml?token=8f3a9c2e7d1b4a6f';
|
||||
const warnings = [{reason: 'secret_query_parameter', name: 'token'}];
|
||||
const privateShare = {
|
||||
shared: false, pending_confirmation: false, can_share: true, card_error: null, warnings,
|
||||
feed_url: secret, id_feed_url: null, discovery: 'running', published: false,
|
||||
};
|
||||
const answers = [];
|
||||
const {store, calls} = podcastsStore({}, {
|
||||
T: {
|
||||
podcastSharePrivate: 'private', podcastSharePublished: 'published', podcastSharePublishing: 'publishing',
|
||||
podcastShareDiscoveryOff: 'discovery off', podcastSharePending: 'pending', podcastShareUnavailable: 'unavailable',
|
||||
podcastWarningSecretQuery: 'parameter «{name}»', podcastWarningPrivateHost: 'host {host}',
|
||||
podcastWarningEntropyQuery: 'value «{name}»', podcastWarningEntropyPath: 'path', podcastWarningOther: 'other',
|
||||
},
|
||||
respond: async () => answers.shift(),
|
||||
});
|
||||
store.current = {podcast_id: 'pod1:x', title: 'Members Only', subscribed: true};
|
||||
store.share = privateShare;
|
||||
store.loadList = () => {};
|
||||
assert.equal(store.shareStatus(), 'private');
|
||||
assert.equal(store.warningText(warnings[0]), 'parameter «token»');
|
||||
assert.equal(store.warningText({reason: 'private_feed_host', host: 'patreon.com'}), 'host patreon.com');
|
||||
assert.equal(store.warningText({reason: 'something_new'}), 'other');
|
||||
|
||||
// The toggle opens the dialog instead of sharing.
|
||||
store.toggleShare();
|
||||
assert.equal(calls.length, 0);
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(store.shareDialog)), {
|
||||
podcastId: 'pod1:x', title: 'Members Only', warnings, feed_url: secret, id_feed_url: null,
|
||||
});
|
||||
store.cancelShare();
|
||||
assert.equal(store.shareDialog, null);
|
||||
assert.equal(calls.length, 0);
|
||||
|
||||
// The feed moved meanwhile: the server asks about the new URL.
|
||||
const moved = Object.assign({}, privateShare, {feed_url: secret + '&v=2', id_feed_url: secret});
|
||||
answers.push({ok: false, status: 409, json: async () => ({error: 'confirm', needs_confirmation: true, share: moved})});
|
||||
store.toggleShare();
|
||||
await store.confirmShare();
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].url, '/api/podcasts/feeds/pod1:x/share');
|
||||
assert.equal(calls[0].init.headers['Content-Type'], 'application/json');
|
||||
assert.deepEqual(JSON.parse(calls[0].init.body), {shared: true, confirm: {feed_url: secret, id_feed_url: null}});
|
||||
assert.equal(store.shareDialog.feed_url, secret + '&v=2');
|
||||
assert.equal(store.shareDialog.id_feed_url, secret);
|
||||
assert.equal(store.shareError, '');
|
||||
|
||||
const published = Object.assign({}, moved, {shared: true, published: true});
|
||||
answers.push({ok: true, status: 200, json: async () => ({podcast: {podcast_id: 'pod1:x', title: 'Members Only', subscribed: true, shared: true}, share: published})});
|
||||
await store.confirmShare();
|
||||
assert.deepEqual(JSON.parse(calls[1].init.body), {
|
||||
shared: true, confirm: {feed_url: secret + '&v=2', id_feed_url: secret},
|
||||
});
|
||||
assert.equal(store.shareDialog, null);
|
||||
assert.equal(store.shareStatus(), 'published');
|
||||
assert.equal(store.sharing, false);
|
||||
|
||||
// Turning it off needs no confirmation.
|
||||
answers.push({ok: true, status: 200, json: async () => ({podcast: store.current, share: privateShare})});
|
||||
await store.toggleShare();
|
||||
assert.deepEqual(JSON.parse(calls[2].init.body), {shared: false});
|
||||
assert.equal(store.shareStatus(), 'private');
|
||||
|
||||
// States of the status line.
|
||||
store.share = Object.assign({}, privateShare, {shared: true, pending_confirmation: true});
|
||||
assert.equal(store.shareStatus(), 'pending');
|
||||
store.share = Object.assign({}, privateShare, {shared: true, discovery: 'off'});
|
||||
assert.equal(store.shareStatus(), 'discovery off');
|
||||
store.share = Object.assign({}, privateShare, {shared: true});
|
||||
assert.equal(store.shareStatus(), 'publishing');
|
||||
|
||||
// A public feed is shared directly; a failure is shown.
|
||||
store.share = Object.assign({}, privateShare, {warnings: []});
|
||||
answers.push({ok: false, status: 409, json: async () => ({error: 'not subscribed'})});
|
||||
await store.toggleShare();
|
||||
assert.deepEqual(JSON.parse(calls[3].init.body), {shared: true});
|
||||
assert.equal(store.shareError, 'not subscribed');
|
||||
assert.equal(store.shareDialog, null);
|
||||
});
|
||||
|
||||
test('playing an episode from the list puts it next in the queue', () => {
|
||||
const played = [];
|
||||
const queue = {
|
||||
|
||||
Reference in new issue
Block a user