Skip to content

Commit

Permalink
post.utilsの追加
Browse files Browse the repository at this point in the history
  • Loading branch information
takecchi committed Feb 14, 2024
1 parent 3b1bdf9 commit 2989098
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/app/(menu)/_utils/post.utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { UserPost } from '@cuculus/cuculus-api';
import { isQuotedRepost, isRepost } from '@/app/(menu)/_utils/post.utils';

describe('PostUtils Integration Test', () => {
// 通常の投稿
const post = {
id: '2',
text: 'Hello.',
originalPostId: undefined,
} as UserPost;

// リポスト
const repost = {
id: '3',
text: undefined,
originalPostId: '1',
} as UserPost;

// 引用リポスト
const quotedRepost = {
id: '4',
text: 'Hello.',
originalPostId: '1',
} as UserPost;

describe('リポストかどうか', () => {
it('通常の投稿', () => {
expect(isRepost(post)).toBe(false);
});

it('リポスト', () => {
expect(isRepost(repost)).toBe(true);
});

it('引用リポスト', () => {
expect(isRepost(quotedRepost)).toBe(false);
});
});

describe('引用リポストかどうか', () => {
it('通常の投稿', () => {
expect(isQuotedRepost(post)).toBe(false);
});

it('リポスト', () => {
expect(isQuotedRepost(repost)).toBe(false);
});

it('引用リポスト', () => {
expect(isQuotedRepost(quotedRepost)).toBe(true);
});
});
});
17 changes: 17 additions & 0 deletions src/app/(menu)/_utils/post.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { UserPost } from '@cuculus/cuculus-api';

/**
* リポストか否か
* @param post
*/
export function isRepost(post: UserPost): boolean {
return post.originalPostId !== undefined && !post.text;
}

/**
* 引用リポストか否か
* @param post
*/
export function isQuotedRepost(post: UserPost): boolean {
return post.originalPostId !== undefined && post.text !== undefined;
}

0 comments on commit 2989098

Please sign in to comment.