-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
160 lines (124 loc) · 3.73 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
/* global describe,it, before */
// Test libraries
var fs = require( 'fs' );
var should = require( 'should' );
var AMT = require('../lib/node-amt.js');
describe( 'AMT test', function() {
var amt, hit, hitType;
var Notification;
var HITType;
var HIT;
var Reward;
// Init library
before( function() {
} );
it( 'Should init', function( done ) {
var config = JSON.parse( fs.readFileSync( __dirname+'/config.json', 'utf8' ) );
( function() {
amt = new AMT( config );
Notification = amt.Notification;
HITType = amt.HITType;
HIT = amt.HIT;
Reward = amt.Reward;
} ).should.not.throw();
done();
} );
it( 'Should create an HITType', function( done ) {
// Create the HITType
hitType = new HITType( {
title: 'Test',
description: 'Test description',
reward: new Reward( 0.01 ),
duration: 60*1, // 1 minute
} );
// Register on AMT
hitType.create( function( err, hitTypePassed ) {
should.not.exist( err );
should.exist( hitTypePassed );
hitTypePassed.should.equal( hitType );
return done();
} );
} );
it( 'Should activate notification for hit type', function( done ) {
// Create notification
var notification = new Notification( {
destination: 'http://volonterio.it/ping',
transport: 'REST',
events: [ 'AssignmentAccepted' ]
} );
hitType.setNotification( notification, done );
} );
it( 'Should create an HIT for the HITType', function( done ) {
// Load Question
var questionXml = fs.readFileSync( __dirname+'/HIT.xml', 'utf8' );
// Create HIT
hit = new HIT( {
hitType: hitType,
question: questionXml,
MaxAssignments: 5,
life: 60*5 // 5 minutes,
} );
hit.create( function ( err, hit, hitTypeId ) {
should.not.exist( err );
should.exist( hit );
should.exist( hitTypeId );
hit.should.be.an.instanceOf( HIT );
hit.should.have.property( 'id' );
hitTypeId.should.be.eql( hitType.id );
return done();
} );
} );
it( 'The HIT should be there', function( done ) {
HIT.get( hit.id, done );
} );
it( 'The HIT should be the first in the search', function( done ) {
var searchOptions = {
SortDirection: 'Descending'
};
HIT.search( searchOptions, function ( err, hits, numResults, page, totalResults ) {
should.not.exist( err );
should.exist( hits );
should.exist( numResults );
should.exist( page );
should.exist( totalResults );
hits.should.be.an.instanceOf( Array );
hits.length.should.be.above( 0 );
page.should.be.eql( 1 );
numResults.should.be.above( 0 );
totalResults.should.be.above( 0 );
should.exist( hits[ 0 ] );
var firstHit = hits[ 0 ];
firstHit.should.have.property( 'id', hit.id );
return done();
} );
} );
it( 'Expire the HIT', function( done ) {
hit.expire( done );
} );
it( 'Dispose the HIT', function( done ) {
hit.dispose( done );
} );
it( 'The HIT should be retrievable', function( done ) {
HIT.get( hit.id, done );
} );
it( '.. but not appear in the search', function( done ) {
var searchOptions = {
SortDirection: 'Descending'
};
HIT.search( searchOptions, function ( err, hits, numResults, page, totalResults ) {
should.not.exist( err );
should.exist( hits );
should.exist( numResults );
should.exist( page );
should.exist( totalResults );
hits.should.be.an.instanceOf( Array );
page.should.be.eql( 1 );
if( hits[ 0 ] ) {
var firstHit = hits[ 0 ];
firstHit.should.have.property( 'id' );
firstHit.id.should.not.be.eql( hit.id );
}
return done();
} );
} );
} );