From 4753e96dcef07e53d5937fa445474b512d277bee Mon Sep 17 00:00:00 2001 From: takonasu Date: Tue, 23 Mar 2021 03:14:59 +0000 Subject: [PATCH] =?UTF-8?q?fix:=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7?= =?UTF-8?q?=E8=AA=AC=E6=98=8E=E3=82=92=E8=A8=98=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/grpc/Information.service.test.ts | 55 +++++++++++++++++----- 1 file changed, 43 insertions(+), 12 deletions(-) diff --git a/__tests__/grpc/Information.service.test.ts b/__tests__/grpc/Information.service.test.ts index 6db746a..103230c 100644 --- a/__tests__/grpc/Information.service.test.ts +++ b/__tests__/grpc/Information.service.test.ts @@ -25,42 +25,73 @@ beforeAll(async () => { }) // ランダム文字列 -let id:string = "" +let id: string = "" const title = Math.random().toString(32).substring(2) const content = Math.random().toString(32).substring(2) const user = 'te_twin' -test('greeting success', (done) => { - const publishedAt = "" - client.addInformation({ user,title,content,publishedAt }, (err, res) => { +test('お知らせがDBに登録できるか', (done) => { + const publishedAt = "2019-10-14 1:54:45" + client.addInformation({ user, title, content, publishedAt }, (err, res) => { expect(err).toBeNull() done() }) }) -test('greeting success', (done) => { +test('未来のお知らせがDBに登録できるか', (done) => { + const publishedAt = "2125-10-14 1:54:45" + client.addInformation({ user, title, content, publishedAt }, (err, res) => { + expect(err).toBeNull() + done() + }) +}) + +test('DBに登録したお知らせが未来公開分以外すべて読み込めるか', (done) => { + client.listInformation({ }, (err, res) => { + expect(res?.Informations[0].title).toEqual(title) + expect(res?.Informations[0].content).toEqual(content) + done() + }) +}) + + + +test('DBに登録したお知らせが指定した数読み込めるか', (done) => { const limit = 1; - client.getInformation({limit}, (err, res) => { + client.getInformation({ limit }, (err, res) => { expect(err).toBeNull() - console.log(res); + expect(res?.Informations.length).toEqual(limit) + expect(res?.Informations[0].title).toEqual(title) + expect(res?.Informations[0].content).toEqual(content) + expect(res?.Informations.length).toEqual(1) done() }) }) -test('greeting success', (done) => { - client.adminListInformation({user}, (err, res) => { + +test('DBに登録したお知らせが未来のも含めて読み込めるか', (done) => { + client.adminListInformation({ user }, (err, res) => { id = res?.Informations[0].id!; expect(err).toBeNull() + expect(res?.Informations.length).toEqual(2) expect(res?.Informations[0].title).toEqual(title) expect(res?.Informations[0].content).toEqual(content) + expect(res?.Informations[1].title).toEqual(title) + expect(res?.Informations[1].content).toEqual(content) done() }) }) -test('greeting success', (done) => { - client.removeInformation({user,id}, (err, res) => { +test('指定したIDのお知らせを消去できるか', (done) => { + client.removeInformation({ user, id }, (err, res) => { expect(err).toBeNull() done() }) }) - +test('正しく消去できているか', (done) => { + client.adminListInformation({ user }, (err, res) => { + expect(err).toBeNull() + expect(res?.Informations.length).toEqual(1) + done() + }) +}) afterAll(stopGrpcServer)