-
Notifications
You must be signed in to change notification settings - Fork 9
/
test.js
71 lines (63 loc) · 1.77 KB
/
test.js
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
import fs from 'fs'
import { TestFunction, createWrite, FunctionType } from "@execution-machine/sdk"
import { state } from './state.js'
import { v4 as uuid } from 'uuid'
import { expect } from 'chai'
const id = uuid()
const functionSource = fs.readFileSync('./handler.js')
const createPost = {
type: 'createPost',
post: {
id,
title: "Hello world",
content: "My first post",
author: "Nader Dabit"
}
}
const updatePost = {
type: 'updatePost',
post: {
id,
title: "Hello world V2",
content: "My updated post!",
author: "Nader Dabit"
}
}
const deletePost = {
type: 'deletePost',
postId: id
}
describe("Testing EXM", function () {
it("Should create a post", async function () {
const testAttempt = await TestFunction({
functionSource,
functionType: FunctionType.JAVASCRIPT,
functionInitState: state,
writes: [createWrite(createPost)]
})
const value = testAttempt.state.posts[id]
expect(value.id).to.equal(id)
expect(value.title).to.equal("Hello world")
})
it("Should update a post", async function () {
const testAttempt = await TestFunction({
functionSource,
functionType: FunctionType.JAVASCRIPT,
functionInitState: state,
writes: [createWrite(createPost), createWrite(updatePost)]
})
const value = testAttempt.state.posts[id]
expect(value.title).to.equal("Hello world V2")
})
it("Should delete a post", async function () {
const testAttempt = await TestFunction({
functionSource,
functionType: FunctionType.JAVASCRIPT,
functionInitState: state,
writes: [createWrite(createPost), createWrite(deletePost)]
})
const value = testAttempt.state.posts
const length = Object.keys(value).length
expect(length).to.equal(0)
})
})