-
Notifications
You must be signed in to change notification settings - Fork 94
/
OutcomesExtension.coffee
88 lines (70 loc) · 2.83 KB
/
OutcomesExtension.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
should = require 'should'
shared = require './shared'
lti = require '../'
describe 'LTI.Extensions.Outcomes', () =>
before () =>
@server = shared.outcomesWebServer()
@provider = new lti.Provider 'key', 'secret'
@server.listen 1337, '127.0.0.1'
req =
url: '/test'
method: 'POST'
body:
ext_outcome_data_values_accepted: 'text,url'
lis_outcome_service_url: "http://127.0.0.1:1337/service/url"
lis_result_sourcedid: "12"
lti_message_type: "basic-lti-launch-request"
lti_version: "LTI-1p0"
get: () -> 'localhost'
@provider.parse_request req
after () =>
@server.close()
@server = null
describe 'replace', () =>
it 'should be able to send a valid request', (next) =>
@provider.outcome_service.send_replace_result .5, (err, result) =>
should.not.exist err
result.should.equal true
next()
it 'should handle a result higher than 1', () =>
@provider.outcome_service.send_replace_result 5, (err, result) =>
should.exist err
result.should.equal false
it 'should handle a result lower than 0', () =>
@provider.outcome_service.send_replace_result -5, (err, result) =>
should.exist err
result.should.equal false
it 'should handle a result that is undefined', () =>
@provider.outcome_service.send_replace_result null, (err, result) =>
should.exist err
result.should.equal false
it 'should be able to send a text payload', () =>
@provider.outcome_service.send_replace_result_with_text .5, 'Hello, world!', (err, result) =>
should.not.exist err
result.should.equal true
it 'should be able to send a text payload', () =>
@provider.outcome_service.send_replace_result_with_url .5, 'http://test.com', (err, result) =>
should.not.exist err
result.should.equal true
it 'should not be able to send a payload that the consumer does not support', () =>
provider = new lti.Provider 'key', 'secret'
provider.parse_request
body:
ext_outcome_data_values_accepted: 'url'
lis_outcome_service_url: "http://127.0.0.1:1337/service/url"
lis_result_sourcedid: "12"
provider.outcome_service.send_replace_result_with_text .5, 'Hello, world!', (err, result) =>
should.exist err
result.should.equal false
describe 'read', () =>
it 'should be able to read a result given an id', (next) =>
@provider.outcome_service.send_read_result (err, result) =>
should.not.exist err
result.should.equal .5
next()
describe 'delete', () =>
it 'should be able to delete a result given an id', (next) =>
@provider.outcome_service.send_delete_result (err, result) =>
should.not.exist err
result.should.equal true
next()