|
| 1 | +import { Client } from '../../dist'; |
| 2 | +import assert from 'assert'; |
| 3 | +import { token } from './utils/config'; |
| 4 | +import { randomString } from './utils/random'; |
| 5 | + |
| 6 | +describe('Articles', () => { |
| 7 | + let newArticleId: string; |
| 8 | + let parentId: number; |
| 9 | + let adminId: number; |
| 10 | + |
| 11 | + before(async () => { |
| 12 | + const randomCollections = await client.helpCenter.collections.list({ |
| 13 | + perPage: 1, |
| 14 | + }); |
| 15 | + const randomAdmins = await client.admins.list(); |
| 16 | + |
| 17 | + parentId = parseInt(randomCollections.data[0].id, 10); |
| 18 | + adminId = parseInt(randomAdmins.admins[0].id, 10); |
| 19 | + }); |
| 20 | + |
| 21 | + const client = new Client({ tokenAuth: { token } }); |
| 22 | + |
| 23 | + it('create', async () => { |
| 24 | + const response = await client.articles.create({ |
| 25 | + title: randomString(), |
| 26 | + description: randomString(), |
| 27 | + body: '<b>Eins Zwei</b>', |
| 28 | + authorId: adminId, |
| 29 | + state: 'draft', |
| 30 | + parentId, |
| 31 | + parentType: 'collection', |
| 32 | + translatedContent: { |
| 33 | + fr: { |
| 34 | + title: 'Allez les verts', |
| 35 | + description: 'French description', |
| 36 | + body: '<p>French body in html</p>', |
| 37 | + author_id: adminId, |
| 38 | + state: 'draft', |
| 39 | + }, |
| 40 | + }, |
| 41 | + }); |
| 42 | + |
| 43 | + newArticleId = response.id; |
| 44 | + assert.notEqual(response, undefined); |
| 45 | + }); |
| 46 | + it('find', async () => { |
| 47 | + const response = await client.articles.find({ id: newArticleId }); |
| 48 | + |
| 49 | + assert.notEqual(response, undefined); |
| 50 | + }); |
| 51 | + it('update', async () => { |
| 52 | + const response = await client.articles.update({ |
| 53 | + id: newArticleId, |
| 54 | + title: 'Biba & Boba', |
| 55 | + }); |
| 56 | + |
| 57 | + assert.notEqual(response, undefined); |
| 58 | + }); |
| 59 | + it('delete', async () => { |
| 60 | + const response = await client.articles.delete({ id: newArticleId }); |
| 61 | + |
| 62 | + assert.notEqual(response, undefined); |
| 63 | + }); |
| 64 | + it('list', async () => { |
| 65 | + const response = await client.articles.list({ page: 1, perPage: 12 }); |
| 66 | + |
| 67 | + assert.notEqual(response, undefined); |
| 68 | + }); |
| 69 | +}); |
0 commit comments