tangled
alpha
login
or
join now
linkat.blue
/
linkat
6
fork
atom
Create your Link in Bio for Bluesky
6
fork
atom
overview
issues
pulls
pipelines
テスト修正
mkizka.dev
2 years ago
747c30c8
f8c9d73a
+38
-10
3 changed files
expand all
collapse all
unified
split
.env.test
app
server
service
boardService
board.spec.ts
vitest
vitest.setup.ts
+4
.env.test
···
0
0
0
0
1
# prisma
2
DATABASE_URL=postgresql://postgres:password@localhost:5432/test
···
1
+
# bsky
2
+
BSKY_PUBLIC_API_URL=https://public.api.example.com
3
+
ATPROTO_PLC_URL=https://plc.example.com
4
+
5
# prisma
6
DATABASE_URL=postgresql://postgres:password@localhost:5432/test
+34
-5
app/server/service/boardService/board.spec.ts
···
27
},
28
};
29
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
30
describe("boardService", () => {
31
describe("createBoard", () => {
32
test("ボードがない場合は新規作成する", async () => {
···
71
const user = await UserFactory.create();
72
server.use(
73
http.get(
74
-
"https://public.api.example.com/xrpc/com.atproto.repo.getRecord",
0
0
0
0
75
() => HttpResponse.json(dummyBoardRecord),
76
),
77
);
···
82
});
83
test("DBにボードがなくPDSから取得したボードが不正ならnullを返す", async () => {
84
// arrange
0
85
server.use(
86
http.get(
87
-
"https://public.api.example.com/xrpc/com.atproto.repo.getRecord",
0
0
0
0
88
() =>
89
HttpResponse.json({
90
...dummyBoardRecord,
···
93
),
94
);
95
// act
96
-
const actual = await boardService.findOrFetchBoard("did:plc:example");
97
// assert
98
expect(mockedLogger.warn).toHaveBeenCalledWith(
99
"PDSからのboardの形式が不正でした",
···
103
});
104
test("DBにもPDSにもボードが無いときはnullを返す", async () => {
105
// arrange
0
106
server.use(
107
http.get(
108
-
"https://public.api.example.com/xrpc/com.atproto.repo.getRecord",
0
0
0
0
109
() => HttpResponse.json({}, { status: 400 }),
110
),
111
);
112
// act
113
-
const actual = await boardService.findOrFetchBoard("did:plc:example");
114
// assert
115
expect(mockedLogger.warn).toHaveBeenCalledWith(
116
"PDSからのboardの取得に失敗しました",
···
27
},
28
};
29
30
+
const dummyDidDocument = (did: string) => ({
31
+
"@context": [
32
+
"https://www.w3.org/ns/did/v1",
33
+
"https://w3id.org/security/suites/secp256k1-2019/v1",
34
+
],
35
+
id: did,
36
+
service: [
37
+
{
38
+
id: "#atproto_pds",
39
+
type: "AtprotoPersonalDataServer",
40
+
serviceEndpoint: "https://pds.example.com",
41
+
},
42
+
],
43
+
});
44
+
45
describe("boardService", () => {
46
describe("createBoard", () => {
47
test("ボードがない場合は新規作成する", async () => {
···
86
const user = await UserFactory.create();
87
server.use(
88
http.get(
89
+
`https://plc.example.com/${encodeURIComponent(user.did)}`,
90
+
() => HttpResponse.json(dummyDidDocument(user.did)),
91
+
),
92
+
http.get(
93
+
"https://pds.example.com/xrpc/com.atproto.repo.getRecord",
94
() => HttpResponse.json(dummyBoardRecord),
95
),
96
);
···
101
});
102
test("DBにボードがなくPDSから取得したボードが不正ならnullを返す", async () => {
103
// arrange
104
+
const user = await UserFactory.create();
105
server.use(
106
http.get(
107
+
`https://plc.example.com/${encodeURIComponent(user.did)}`,
108
+
() => HttpResponse.json(dummyDidDocument(user.did)),
109
+
),
110
+
http.get(
111
+
"https://pds.example.com/xrpc/com.atproto.repo.getRecord",
112
() =>
113
HttpResponse.json({
114
...dummyBoardRecord,
···
117
),
118
);
119
// act
120
+
const actual = await boardService.findOrFetchBoard(user.did);
121
// assert
122
expect(mockedLogger.warn).toHaveBeenCalledWith(
123
"PDSからのboardの形式が不正でした",
···
127
});
128
test("DBにもPDSにもボードが無いときはnullを返す", async () => {
129
// arrange
130
+
const user = await UserFactory.create();
131
server.use(
132
http.get(
133
+
`https://plc.example.com/${encodeURIComponent(user.did)}`,
134
+
() => HttpResponse.json(dummyDidDocument(user.did)),
135
+
),
136
+
http.get(
137
+
"https://pds.example.com/xrpc/com.atproto.repo.getRecord",
138
() => HttpResponse.json({}, { status: 400 }),
139
),
140
);
141
// act
142
+
const actual = await boardService.findOrFetchBoard(user.did);
143
// assert
144
expect(mockedLogger.warn).toHaveBeenCalledWith(
145
"PDSからのboardの取得に失敗しました",
-5
vitest/vitest.setup.ts
···
5
afterEach(() => {
6
vi.useRealTimers();
7
});
8
-
vi.mock("~/utils/env", () => ({
9
-
env: {
10
-
BSKY_PUBLIC_API_URL: "https://public.api.example.com",
11
-
},
12
-
}));
13
14
// prisma
15
vi.mock("~/server/service/prisma", () => ({
···
5
afterEach(() => {
6
vi.useRealTimers();
7
});
0
0
0
0
0
8
9
// prisma
10
vi.mock("~/server/service/prisma", () => ({