-
Notifications
You must be signed in to change notification settings - Fork 4
/
bugtik.spec.coffee
executable file
·110 lines (106 loc) · 3.26 KB
/
bugtik.spec.coffee
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
describe 'bugtik', ->
Q = require 'q'
beforeEach ->
@hybind = require './index.coffee'
@api = @hybind 'http://localhost:8080/api/'
it 'should load api', (done) ->
api = @api
@api.$load()
.then ->
expect(api.tickets).toBeDefined()
expect(api.projects).toBeDefined()
expect(api.severities).toBeDefined()
done()
.done()
it 'should create and assign severity', (done) ->
api = @api
api.$bind 'severities', []
api.$bind 'colors', []
important = {}
yellow = code: '#EEEE11'
api.severities.$bind(important, 'important').$save()
.then ->
api.severities.$load()
.then ->
found = (s for s in api.severities.filter (s) -> s.name == 'important')
expect(found.length).toBeGreaterThan 0
api.colors.$load()
.then ->
api.colors.$bind(yellow, 'yellow').$save()
.then ->
important.$bind('color').$set yellow
.then ->
api.$bind('tickets', []).$load()
.then ->
api.tickets[0].$bind('severity').$load()
.then ->
expect(api.tickets[0].severity.name).toBe 'normal'
api.tickets[0].severity.$set important
.then ->
api.tickets[0].severity.$load()
.then ->
api.tickets[0].severity.color.$load()
.then ->
expect(api.tickets[0].severity.color.name).toBe 'yellow'
api.tickets[0].severity.$set api.severities[1]
.then ->
api.tickets[0].severity.$load()
.then ->
api.tickets[0].severity.color.$load()
.then ->
expect(api.tickets[0].severity.color.name).toBe 'blue'
important.$delete()
.then ->
done()
it 'should move tickets across projects', (done) ->
api = @api
api.$bind 'tickets', []
api.$bind 'projects', []
projects = api.projects
tickets = []
check = (tickets) ->
two = tickets.filter (ticket) -> ticket.summary == '2'
three = tickets.filter (ticket) -> ticket.summary == '3'
return two.length > 0 and three.length > 0
projects.$load()
.then ->
projects[0].$bind 'tickets', []
api.tickets.$create summary: '2'
.then (ticket) ->
tickets.push ticket
projects[0].tickets.$add ticket
.then ->
api.tickets.$create summary: '3'
.then (ticket) ->
id = ticket.$bind.self.split('/')[-1..]
tickets.push ticket
projects[0].tickets.$bind ticket
expect(ticket.$bind.ref).toBe 'http://localhost:8080/api/projects/1/tickets/'+id
projects[0].tickets.$add ticket
.then ->
projects[0].tickets.$load()
.then ->
expect(check projects[0].tickets).toBe true
projects[1].$bind 'tickets', []
projects[1].tickets.$add tickets
.then ->
projects[0].tickets.$load()
.then ->
expect(check projects[0].tickets).toBe false
projects[1].tickets.$load()
.then ->
expect(check projects[1].tickets).toBe true
ticket.$delete() for ticket in projects[1].tickets
done()
.done()
it 'should find by owner', (done) ->
@api.$load().then (api) ->
api.tickets.$bind('search/findByOwner', []).$load(owner: 'me')
.then (results) ->
expect(results.length).toBe 1
expect(results[0].owner).toBe 'me'
results[0].severity.$load()
.then (severity) ->
expect(severity.name).toBe 'normal'
done()
.done()