forked from ProtoSchool/protoschool.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorials.spec.js
More file actions
147 lines (126 loc) · 4.41 KB
/
Copy pathtutorials.spec.js
File metadata and controls
147 lines (126 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const api = require('../../../src/api')
const setup = require('../../../jest/helpers/setup')
const fixtures = require('../../../jest/helpers/fixtures')
const asserts = require('../helpers/asserts')
const runners = require('../helpers/runners')
describe('protowizard', () => {
let lastTutorialId
beforeAll(async () => {
lastTutorialId = (await api.tutorials.list.getLatest()).id
})
afterEach(async () => {
await setup.restoreData(lastTutorialId)
})
describe('1. create tutorial', () => {
test('1.1. should create tutorial (skips lesson creation)', async () => {
const { tutorial, expected } = await fixtures.generateTutorial()
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: false } // no to create first lesson
])
asserts.assertNewTutorial({
context: { lastTutorialId },
expected,
result: await api.tutorials.getByUrl(tutorial.url)
})
})
test('1.2. should create tutorial with one text lesson', async () => {
const { tutorial, lessons, expected } = await fixtures.generateTutorial({
lessons: 1
})
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: true }, // yes to create the first lesson
lessons[0],
{ confirm: false }, // no to create another lesson
{ confirm: false } // no to create the first resource
])
asserts.assertNewTutorial({
context: { lastTutorialId },
expected,
result: await api.tutorials.getByUrl(tutorial.url)
})
})
test('1.3. should create tutorial with two text lessons', async () => {
const { tutorial, lessons, expected } = await fixtures.generateTutorial({
lessons: 2
})
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: true }, // yes to create the first lesson
lessons[0],
{ confirm: true }, // yes to create another lesson
lessons[1],
{ confirm: false }, // no to create another lesson
{ confirm: false } // no to create the first resource
])
asserts.assertNewTutorial({
context: { lastTutorialId },
expected,
result: await api.tutorials.getByUrl(tutorial.url)
})
})
test('1.4. should create tutorial with one lesson and one resource', async () => {
const { tutorial, lessons, resources, expected } = await fixtures.generateTutorial({
lessons: 1,
resources: 1
})
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: true }, // yes to create the first lesson
lessons[0],
{ confirm: false }, // no to create another lesson
{ confirm: true }, // yes to create the first resource
resources[0],
{ confirm: false } // no to create another resource
])
asserts.assertNewTutorial({
context: { lastTutorialId },
expected,
result: await api.tutorials.getByUrl(tutorial.url)
})
})
test('1.5. should create tutorial with one lesson and two resources', async () => {
const { tutorial, lessons, resources, expected } = await fixtures.generateTutorial({
lessons: 1,
resources: 2
})
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: true }, // yes to create the first lesson
lessons[0],
{ confirm: false }, // no to create another lesson
{ confirm: true }, // yes to create the first resource
resources[0],
{ confirm: true }, // yes to create another resource
resources[1],
{ confirm: false } // no to create another resource
])
asserts.assertNewTutorial({
context: { lastTutorialId },
expected,
result: await api.tutorials.getByUrl(tutorial.url)
})
})
test('1.6. should not allow to create two tutorials with the same title or url', async () => {
const { tutorial } = await fixtures.generateTutorial()
await runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: false } // no to create first lesson
])
await expect(
runners.protowizard([
{ type: 'tutorial' },
tutorial,
{ confirm: false } // no to create first lesson
])
).rejects.toThrow('INQUIRER VALIDATION FAILED')
})
})
})