L'ordine dei tipi (storie, evidenza, post, reel, taggati) ora vale anche per il singolo account: nella scheda account → Impostazioni si sceglie «Come le impostazioni generali» o un ordine suo, con lo stesso elenco da trascinare (o Su/Giù da tastiera) di Limiti e comportamento, ora un modulo solo (download-order.js). Il motore pesa le visite con l'ordine dell'account, la coda dei file mette ogni file al posto del suo tipo nell'ordine del suo account, stabile dentro il tipo (scadenza, scoperta, elemento, posizione). Perché nessun tipo resti fermo per sempre quando il tetto dei dati finisce prima della coda, un posto su otto di ogni giro della coda va al file che aspetta da più tempo, di qualunque tipo. I reel non si inventano (regola 9): un post è reel se viene dalla scheda Reel o se la risposta ha product_type «clips», valore visto nei campioni ripuliti. Il segno si scrive da solo e non si toglie mai, così una copia vecchia non sposta di nuovo i file in coda. Migrazione 0002_ordine_scaricamento (account.download_order, entry.is_reel): prende il primo numero dopo quelle unite, E1 userà il successivo. Prove su motore (seme fisso), coda, lettori, ricette e API; dimostrazione con un account che ha l'ordine suo; guida e decisioni aggiornate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
6.4 KiB
C#
100 lines
6.4 KiB
C#
using System.Net;
|
|
using System.Text.Json;
|
|
using Febe.Core.Domain;
|
|
using Febe.Core.Engine;
|
|
using Febe.Tests.Support;
|
|
using Febe.Tests.Web.Part2Support;
|
|
using Febe.Tests.Web.Support;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// What the Dashboard and «Cosa scaricare prima» ask the server (spec §7.2, §7.9, tappa D1): the thumbnails of a line of
|
|
/// the history, and the order of the kinds saved with the limits.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class DashboardApiTests
|
|
{
|
|
[TestMethod]
|
|
public async Task ALineOfTheHistoryGetsTheEntriesItSavedNewestFirst()
|
|
{
|
|
await using var server = await Part2.StartAsync();
|
|
var marta = await server.Db.Accounts.AddAsync(Make.Account("marta.prova"));
|
|
var luca = await server.Db.Accounts.AddAsync(Make.Account("luca.prova"));
|
|
var start = Make.T0.AddHours(1);
|
|
await server.Db.Entries.AddAsync(Make.Entry(marta.Id, "prima", Make.T0) with { DiscoveredAt = start.AddMinutes(-5) }, [Make.Photo()]);
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
await server.Db.Entries.AddAsync(Make.Entry(marta.Id, $"nuovo{i}", Make.T0) with { DiscoveredAt = start.AddSeconds(10 * (i + 1)) }, [Make.Photo()]);
|
|
}
|
|
|
|
await server.Db.Entries.AddAsync(Make.Entry(luca.Id, "altro", Make.T0) with { DiscoveredAt = start.AddSeconds(15) }, [Make.Photo()]);
|
|
|
|
var from = Uri.EscapeDataString(start.ToString("O"));
|
|
var to = Uri.EscapeDataString(start.AddMinutes(1).ToString("O"));
|
|
var arrived = await server.GetJsonAsync($"/api/activity/arrived?account={marta.Id}&from={from}&to={to}&limit=2");
|
|
Assert.AreEqual(3, arrived.Int("total"), "only what that recipe saved, of that account");
|
|
var tiles = arrived.Items("tiles").ToList();
|
|
Assert.HasCount(2, tiles, "at most what the line shows");
|
|
Assert.IsTrue(tiles.All(t => t.Int("accountId") == marta.Id));
|
|
|
|
var (status, _, _) = await server.GetAsync($"/api/activity/arrived?account={marta.Id}&from={to}&to={from}");
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, status, "the end before the start");
|
|
(status, _, _) = await server.GetAsync("/api/activity/arrived?account=uno");
|
|
Assert.AreEqual(HttpStatusCode.BadRequest, status);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task TheOrderOfTheKindsIsSavedWithTheLimitsAndKeptWhenNotSent()
|
|
{
|
|
await using var server = await Part2.StartAsync();
|
|
var limits = await server.GetJsonAsync("/api/settings/limits");
|
|
CollectionAssert.AreEqual(new[] { "storie", "evidenza", "post", "reel", "taggati" }, limits.Items("downloadOrder").Select(k => k.GetString()).ToArray());
|
|
|
|
var (status, saved) = await server.SendJsonAsync(HttpMethod.Put, "/api/settings/limits",
|
|
new { profile = "prudent", pace = "natural", gradualStart = true, activeDays = new[] { 0, 1, 2, 3, 4, 5, 6 }, downloadOrder = new[] { "taggati", "post" } });
|
|
Assert.AreEqual(HttpStatusCode.OK, status);
|
|
CollectionAssert.AreEqual(new[] { "taggati", "post", "storie", "evidenza", "reel" }, saved.Items("downloadOrder").Select(k => k.GetString()).ToArray());
|
|
Assert.AreEqual("taggati,post,storie,evidenza,reel", await server.Db.Settings.GetAsync(DownloadOrder.SettingKey));
|
|
|
|
(status, saved) = await server.SendJsonAsync(HttpMethod.Put, "/api/settings/limits",
|
|
new { profile = "prudent", pace = "natural", gradualStart = true, activeDays = new[] { 0, 1, 2, 3, 4, 5, 6 } });
|
|
Assert.AreEqual(HttpStatusCode.OK, status);
|
|
Assert.AreEqual("taggati", saved.Items("downloadOrder").First().GetString(), "not sent: the stored order stays");
|
|
|
|
await server.SendJsonAsync(HttpMethod.Put, "/api/settings/limits",
|
|
new { profile = "prudent", pace = "natural", gradualStart = true, activeDays = new[] { 0, 1, 2, 3, 4, 5, 6 }, downloadOrder = DownloadOrder.Default.Kinds.Select(DownloadOrder.NameOf).ToArray() });
|
|
Assert.IsNull(await server.Db.Settings.GetAsync(DownloadOrder.SettingKey), "the default order is no stored value");
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task AnAccountFollowsTheGeneralOrderOrHasOneOfItsOwn()
|
|
{
|
|
await using var server = await Part2.StartAsync();
|
|
await server.Db.Settings.SetAsync(DownloadOrder.SettingKey, "post,storie");
|
|
var account = await server.Db.Accounts.AddAsync(Make.Account("marta.prova"));
|
|
|
|
var detail = await server.GetJsonAsync($"/api/accounts/{account.Id}");
|
|
Assert.AreEqual(JsonValueKind.Null, detail.GetProperty("settings").GetProperty("downloadOrder").ValueKind, "«Come le impostazioni generali»");
|
|
CollectionAssert.AreEqual(new[] { "post", "storie", "evidenza", "reel", "taggati" }, detail.Items("generalDownloadOrder").Select(k => k.GetString()).ToArray());
|
|
|
|
// «Un ordine suo»: saved with the other settings, completed to the five kinds.
|
|
var settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(detail.GetProperty("settings").GetRawText())!;
|
|
settings["downloadOrder"] = JsonSerializer.SerializeToElement(new[] { "reel", "taggati" });
|
|
var (status, saved) = await server.SendJsonAsync(HttpMethod.Put, $"/api/accounts/{account.Id}/settings", settings);
|
|
Assert.AreEqual(HttpStatusCode.OK, status);
|
|
CollectionAssert.AreEqual(new[] { "reel", "taggati", "storie", "evidenza", "post" }, saved.GetProperty("settings").Items("downloadOrder").Select(k => k.GetString()).ToArray());
|
|
Assert.AreEqual("reel,taggati,storie,evidenza,post", (await server.Db.Accounts.GetAsync(account.Id))!.DownloadOrder);
|
|
|
|
// «Tieni aggiornato» from the table keeps it; back to «Come le impostazioni generali» with null.
|
|
(status, _) = await server.SendJsonAsync(HttpMethod.Post, $"/api/accounts/{account.Id}/keep-updated", new { value = false });
|
|
Assert.AreEqual(HttpStatusCode.OK, status);
|
|
Assert.AreEqual("reel,taggati,storie,evidenza,post", (await server.Db.Accounts.GetAsync(account.Id))!.DownloadOrder);
|
|
settings = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>((await server.GetJsonAsync($"/api/accounts/{account.Id}")).GetProperty("settings").GetRawText())!;
|
|
settings["downloadOrder"] = JsonSerializer.SerializeToElement<string[]?>(null);
|
|
(status, _) = await server.SendJsonAsync(HttpMethod.Put, $"/api/accounts/{account.Id}/settings", settings);
|
|
Assert.AreEqual(HttpStatusCode.OK, status);
|
|
Assert.IsNull((await server.Db.Accounts.GetAsync(account.Id))!.DownloadOrder);
|
|
}
|
|
}
|