|
1 | 1 | const { getDevPost } = require('../src/index');
|
| 2 | +const { getMediumPost } = require('../src/index'); |
2 | 3 |
|
3 | 4 | describe('getDevPost function', () => {
|
4 | 5 | it('should be defined', () => {
|
@@ -52,3 +53,56 @@ describe('getDevPost function', () => {
|
52 | 53 | }).rejects.toThrow(TypeError);
|
53 | 54 | });
|
54 | 55 | });
|
| 56 | + |
| 57 | +describe('getMediumPost function', () => { |
| 58 | + it('should be defined', () => { |
| 59 | + expect(getMediumPost).toBeDefined(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should return array', async () => { |
| 63 | + const result = await getMediumPost({ |
| 64 | + user: 'arifszn', |
| 65 | + }); |
| 66 | + |
| 67 | + expect(Array.isArray(result)).toBe(true); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should contain properties', async () => { |
| 71 | + const result = await getMediumPost({ |
| 72 | + user: 'arifszn', |
| 73 | + }); |
| 74 | + |
| 75 | + expect(result[0]).toEqual( |
| 76 | + expect.objectContaining({ |
| 77 | + title: expect.any(String), |
| 78 | + description: expect.any(String), |
| 79 | + thumbnail: expect.any(String), |
| 80 | + link: expect.any(String), |
| 81 | + categories: expect.any(Array), |
| 82 | + publishedAt: expect.any(Date), |
| 83 | + }) |
| 84 | + ); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should return empty array for empty user', async () => { |
| 88 | + const result = await getMediumPost({ user: '' }); |
| 89 | + |
| 90 | + expect(Array.isArray(result)).toBe(true); |
| 91 | + expect(result.length).toBe(0); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should return empty array for invalid user', async () => { |
| 95 | + const result = await getMediumPost({ |
| 96 | + user: 'asdsfdsdfsdfsdfsdf-sdfsdfsdfs-sdfsdfsd-123-4234332', |
| 97 | + }); |
| 98 | + |
| 99 | + expect(Array.isArray(result)).toBe(true); |
| 100 | + expect(result.length).toBe(0); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should throw error for undefined user', () => { |
| 104 | + expect(async () => { |
| 105 | + await getMediumPost(); |
| 106 | + }).rejects.toThrow(TypeError); |
| 107 | + }); |
| 108 | +}); |
0 commit comments