BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f99e8c07
Commit
f99e8c07
authored
May 12, 2017
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'remove-vue-from-poll_spec-fix-transient-failures' into 'master'
Fix poll_spec transient failures See merge request !11264
parents
f938f944
55b6232c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
71 deletions
+22
-71
poll_spec.js
spec/javascripts/lib/utils/poll_spec.js
+22
-71
No files found.
spec/javascripts/lib/utils/poll_spec.js
View file @
f99e8c07
import
Vue
from
'vue'
;
import
VueResource
from
'vue-resource'
;
import
Poll
from
'~/lib/utils/poll'
;
Vue
.
use
(
VueResource
);
const
waitForAllCallsToFinish
=
(
service
,
waitForCount
,
successCallback
)
=>
{
const
timer
=
()
=>
{
setTimeout
(()
=>
{
...
...
@@ -12,45 +8,33 @@ const waitForAllCallsToFinish = (service, waitForCount, successCallback) => {
}
else
{
timer
();
}
},
5
);
},
0
);
};
timer
();
};
class
ServiceMock
{
constructor
(
endpoint
)
{
this
.
service
=
Vue
.
resource
(
endpoint
);
}
function
mockServiceCall
(
service
,
response
,
shouldFail
=
false
)
{
const
action
=
shouldFail
?
Promise
.
reject
:
Promise
.
resolve
;
const
responseObject
=
response
;
if
(
!
responseObject
.
headers
)
responseObject
.
headers
=
{};
fetch
()
{
return
this
.
service
.
get
();
}
service
.
fetch
.
and
.
callFake
(
action
.
bind
(
Promise
,
responseObject
));
}
describe
(
'Poll'
,
()
=>
{
let
callbacks
;
let
service
;
const
service
=
jasmine
.
createSpyObj
(
'service'
,
[
'fetch'
])
;
const
callbacks
=
jasmine
.
createSpyObj
(
'callbacks'
,
[
'success'
,
'error'
])
;
beforeEach
(()
=>
{
callbacks
=
{
success
:
()
=>
{},
error
:
()
=>
{},
};
service
=
new
ServiceMock
(
'endpoint'
);
spyOn
(
callbacks
,
'success'
);
spyOn
(
callbacks
,
'error'
);
spyOn
(
service
,
'fetch'
).
and
.
callThrough
();
afterEach
(()
=>
{
callbacks
.
success
.
calls
.
reset
();
callbacks
.
error
.
calls
.
reset
();
service
.
fetch
.
calls
.
reset
();
});
it
(
'calls the success callback when no header for interval is provided'
,
(
done
)
=>
{
const
successInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
200
}));
};
Vue
.
http
.
interceptors
.
push
(
successInterceptor
);
mockServiceCall
(
service
,
{
status
:
200
});
new
Poll
({
resource
:
service
,
...
...
@@ -63,18 +47,12 @@ describe('Poll', () => {
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
successInterceptor
);
done
();
}
,
0
);
});
});
it
(
'calls the error callback whe the http request returns an error'
,
(
done
)
=>
{
const
errorInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
500
}));
};
Vue
.
http
.
interceptors
.
push
(
errorInterceptor
);
mockServiceCall
(
service
,
{
status
:
500
},
true
);
new
Poll
({
resource
:
service
,
...
...
@@ -86,42 +64,29 @@ describe('Poll', () => {
waitForAllCallsToFinish
(
service
,
1
,
()
=>
{
expect
(
callbacks
.
success
).
not
.
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
errorInterceptor
);
done
();
});
});
it
(
'should call the success callback when the interval header is -1'
,
(
done
)
=>
{
const
intervalInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
200
,
headers
:
{
'poll-interval'
:
-
1
}
}));
};
Vue
.
http
.
interceptors
.
push
(
intervalInterceptor
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'poll-interval'
:
-
1
}
});
new
Poll
({
resource
:
service
,
method
:
'fetch'
,
successCallback
:
callbacks
.
success
,
errorCallback
:
callbacks
.
error
,
}).
makeRequest
();
setTimeout
(()
=>
{
}).
makeRequest
().
then
(()
=>
{
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
intervalInterceptor
);
done
();
}
,
0
);
}
).
catch
(
done
.
fail
);
});
it
(
'starts polling when http status is 200 and interval header is provided'
,
(
done
)
=>
{
const
pollInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
200
,
headers
:
{
'poll-interval'
:
2
}
}));
};
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'poll-interval'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -141,19 +106,13 @@ describe('Poll', () => {
expect
(
callbacks
.
success
).
toHaveBeenCalled
();
expect
(
callbacks
.
error
).
not
.
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
describe
(
'stop'
,
()
=>
{
it
(
'stops polling when method is called'
,
(
done
)
=>
{
const
pollInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
200
,
headers
:
{
'poll-interval'
:
2
}
}));
};
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'poll-interval'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -174,8 +133,6 @@ describe('Poll', () => {
expect
(
service
.
fetch
).
toHaveBeenCalledWith
({
page
:
1
});
expect
(
Polling
.
stop
).
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
...
...
@@ -183,11 +140,7 @@ describe('Poll', () => {
describe
(
'restart'
,
()
=>
{
it
(
'should restart polling when its called'
,
(
done
)
=>
{
const
pollInterceptor
=
(
request
,
next
)
=>
{
next
(
request
.
respondWith
(
JSON
.
stringify
([]),
{
status
:
200
,
headers
:
{
'poll-interval'
:
2
}
}));
};
Vue
.
http
.
interceptors
.
push
(
pollInterceptor
);
mockServiceCall
(
service
,
{
status
:
200
,
headers
:
{
'poll-interval'
:
1
}
});
const
Polling
=
new
Poll
({
resource
:
service
,
...
...
@@ -215,8 +168,6 @@ describe('Poll', () => {
expect
(
Polling
.
stop
).
toHaveBeenCalled
();
expect
(
Polling
.
restart
).
toHaveBeenCalled
();
Vue
.
http
.
interceptors
=
_
.
without
(
Vue
.
http
.
interceptors
,
pollInterceptor
);
done
();
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment