Skip to content

Commit

Permalink
💚 24以内交流のテストケースを増やした
Browse files Browse the repository at this point in the history
  • Loading branch information
dicenull committed Sep 3, 2024
1 parent d3dea02 commit a1eef8e
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 13 deletions.
2 changes: 2 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 90 additions & 13 deletions tests/distilled_user_test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,98 @@
import {
afterAll,
afterEach,
beforeAll,
describe,
it,
} from "https://deno.land/std@0.193.0/testing/bdd.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/mod.ts";
import { distilledUserWithin24Hours } from "../library/distilled_user_within_24hour.js";
import { getNowTime } from "../library/get_time.js";

Deno.test("24時間以内に交流したユーザだけ取得できる", async () => {
const kv = await Deno.openKv();
const user1 = { User: 2, time: getNowTime() };
const user2 = { User: 3, time: getNowTime() };
kv.set(["SP", 1, 2], user1);
kv.set(["SP", 2, 3], user2);
describe("24時間以内に交流したユーザ判定", () => {
let kv;

const userList = await distilledUserWithin24Hours(1, kv);
beforeAll(async () => {
kv = await Deno.openKv(":memory:");
});

assertEquals(userList, [{
sourceId: 1,
destinationId: 2,
time: user1.time,
}]);
afterAll(async () => {
await kv.close();
});

await kv.close();
afterEach(async () => {
for await (const entry of kv.list({ prefix: [] })) {
await kv.delete(entry.key);
}
});

it("ユーザがSPを贈ると、交流したとこになる", async () => {
const user = { User: 2, time: getNowTime() };
kv.set(["SP", 1, 100], user);

const userList = await distilledUserWithin24Hours(1, kv);

assertEquals(userList, [{
sourceId: 1,
destinationId: 2,
time: user.time,
}]);
});

it("ユーザがSPを貰っても、交流したことになる", async () => {
const user = { User: 1, time: getNowTime() };
kv.set(["SP", 2, 100], user);

const userList = await distilledUserWithin24Hours(1, kv);

assertEquals(userList, [{
sourceId: 2,
destinationId: 1,
time: user.time,
}]);
});

it("交流履歴があるユーザだけ取得できる", async () => {
const user1 = { User: 2, time: getNowTime() };
const user2 = { User: 3, time: getNowTime() };
kv.set(["SP", 1, 100], user1);
kv.set(["SP", 2, 101], user2);

const userList = await distilledUserWithin24Hours(1, kv);

assertEquals(userList, [{
sourceId: 1,
destinationId: 2,
time: user1.time,
}]);
});

it("24時間以内に交流したユーザだけ取得できる", async () => {
// 1日前に交流したユーザ
const user1 = {
User: 2,
time: new Date(getNowTime()).getTime() - 24 * 60 * 60 * 1000,
};
// 1時間前に交流したユーザ
const user2 = {
User: 3,
time: new Date(getNowTime()).getTime() - 60 * 60 * 1000,
};
// 1週間に交流したユーザ
const user3 = {
User: 4,
time: new Date(getNowTime()).getTime() - 7 * 24 * 60 * 60 * 1000,
};
kv.set(["SP", 1, 100], user1);
kv.set(["SP", 1, 101], user2);
kv.set(["SP", 1, 102], user3);

const userList = await distilledUserWithin24Hours(1, kv);

assertEquals(userList, [{
sourceId: 1,
destinationId: 3,
time: user2.time,
}]);
});
});

0 comments on commit a1eef8e

Please sign in to comment.