Commit 1fd49dca authored by Cornee Traas's avatar Cornee Traas
Browse files

Use regex with moxios

parent 7687a5c9
Pipeline #2531 failed with stages
in 8 minutes and 39 seconds
......@@ -157,7 +157,7 @@ export default {
},
getPlatforms() {
return axios.get(this.apiUrl() + "/p/", {
return axios.get(this.apiUrl() + "/p", {
headers: this.authHeader(),
})
},
......
<template>
<button class="backbutton" type="button" @click="callback"><span v-if="!minimized" class="backbutton-text">Up</span><i class="fa fa-level-up nav-icon"></i></button>
<button class="backbutton" type="button" @click="callback">
<span v-if="!minimized" class="backbutton-text">Up</span>
<i class="fa fa-level-up nav-icon"></i>
</button>
</template>
<script>
export default {
name: "backbutton",
name: "BackButton",
methods: {},
props: {
callback: Function,
......
......@@ -50,7 +50,7 @@ describe('Courses.vue', () => {
expect(wrapper.is(Courses)).toBe(true)
})
it('requests and shows the right data', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/course-analytics/", {
moxios.stubRequest(/.*course-analytics*./, {
status: 200,
response: [{
"id": "qvkru5bqEeigcQ6ACV18LA",
......@@ -84,7 +84,7 @@ describe('Courses.vue', () => {
})
it('handles empty data', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/course-analytics/", {
moxios.stubRequest(/.*course-analytics*./, {
status: 200,
response: [],
})
......@@ -96,7 +96,7 @@ describe('Courses.vue', () => {
})
it('handles api error', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/course-analytics/", {
moxios.stubRequest(/.*course-analytics*./, {
status: 403,
response: [],
})
......
......@@ -104,17 +104,17 @@ describe('DefaultContainer.vue', () => {
it('Check videos rejected', (done) => {
// For coverability, nothing is done here, nav remains empty
moxios.stubRequest(util.platformUrl() + '/video-analytics/1/', {
moxios.stubRequest(/.*video-analytics.1.*/, {
status: 403,
response: {
"Error": "Error occurred",
},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test/videos")
wrapper.vm.setNavigation("/p/default/test/videos")
moxios.wait(function () {
expect(wrapper.vm.top_nav[3].length).toBe(0)
expect(wrapper.vm.top_nav[4].length).toBe(0)
done();
})
})
......@@ -141,17 +141,17 @@ describe('DefaultContainer.vue', () => {
// })
it('Check quizzes rejected', (done) => {
moxios.stubRequest(util.platformUrl() + '/quiz-analytics/1/', {
moxios.stubRequest(/.*quiz-analytics.1.*/, {
status: 403,
response: {
"Error": "Error occurred",
},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test/quizzes")
wrapper.vm.setNavigation("/p/default/test/quizzes")
moxios.wait(function () {
expect(wrapper.vm.top_nav[3].length).toBe(0)
expect(wrapper.vm.top_nav[4].length).toBe(0)
done();
})
})
......@@ -208,7 +208,7 @@ describe('DefaultContainer.vue', () => {
// Connection bar
it('Test authentication', (done) => {
moxios.stubRequest(util.apiUrl() + '/testview/', {
moxios.stubRequest(/.*testview.*/, {
status: 200,
response: {
"success": "You have a valid access token",
......@@ -222,7 +222,7 @@ describe('DefaultContainer.vue', () => {
})
it('Test authentication decline', (done) => {
moxios.stubRequest(util.apiUrl() + '/testview/', {
moxios.stubRequest(/.*testview*/, {
status: 403,
response: {},
});
......@@ -235,7 +235,7 @@ describe('DefaultContainer.vue', () => {
// Actions modal
it('action button click shows actions modal and contains right content', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/default/1/', {
moxios.stubRequest(/.*actions\/default*/, {
status: 200,
response: [{
title: "action 1",
......@@ -243,7 +243,7 @@ describe('DefaultContainer.vue', () => {
}, ],
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......@@ -259,14 +259,14 @@ describe('DefaultContainer.vue', () => {
})
it('action button click shows actions modal and shows error', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/default/1/', {
moxios.stubRequest(/.*actions\/default*/, {
status: 403,
response: {
error: "error",
},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......@@ -283,7 +283,7 @@ describe('DefaultContainer.vue', () => {
// Add action modal
it('Add action modal is reachable', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/default/1/', {
moxios.stubRequest(/.*actions\/default*/, {
status: 200,
response: [{
title: "action 1",
......@@ -291,7 +291,7 @@ describe('DefaultContainer.vue', () => {
}, ],
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......@@ -310,14 +310,14 @@ describe('DefaultContainer.vue', () => {
})
it('Test if adding a action works', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/', {
moxios.stubRequest(/.*actions\/*/, {
status: 200,
response: {
success: "success",
},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......@@ -338,14 +338,14 @@ describe('DefaultContainer.vue', () => {
})
it('Test if adding an empty action shows an error message', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/', {
moxios.stubRequest(/.*actions\/*/, {
status: 200,
response: {
success: "success",
},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......@@ -369,7 +369,7 @@ describe('DefaultContainer.vue', () => {
// Delete action modal
it('Test if an action can be deleted', (done) => {
moxios.stubRequest(util.apiUrl() + '/actions/default/1/', {
moxios.stubRequest(/.*actions\/default*/, {
status: 200,
response: [{
pk: 1,
......@@ -379,12 +379,12 @@ describe('DefaultContainer.vue', () => {
description: "description 1",
}, ],
});
moxios.stubRequest(util.apiUrl() + '/actions/1/', {
moxios.stubRequest(/.*actions\/1/, {
status: 204,
response: {},
});
const wrapper = mountComponent()
wrapper.vm.setNavigation("/coursera/test");
wrapper.vm.setNavigation("/p/default/test");
moxios.wait(function () {
expect(wrapper.vm.showActionsModal).toBe(false)
......
......@@ -53,7 +53,9 @@ describe('Home.vue', () => {
expect(wrapper.is(Home)).toBe(true)
})
it('Test if the homepage shows correct statistics for separate courses, and combined statistics are correct.', (done) => {
moxios.stubRequest(util.platformUrl() + '/course-analytics/', {
store.state.filters.to = null;
store.state.filters.from = null;
moxios.stubRequest(/.*course-analytics.*/, {
status: 200,
response: [{
enrolled_learners: 6,
......@@ -71,9 +73,9 @@ describe('Home.vue', () => {
enrolled_learners: 7,
finished_learners: 5,
leaving_learners: 43253,
name: "test_name",
name: "test_name2",
paying_learners: 324,
slug: "test-name",
slug: "test-name2",
ratings: [
[1, 0, ],
],
......@@ -83,7 +85,7 @@ describe('Home.vue', () => {
const wrapper = mountComponent();
moxios.wait(function () {
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.html()).toContain('Coursera')
expect(wrapper.html()).toContain('Testing Platform')
expect(wrapper.html()).toContain('test_name')
// Test enrolled learner separate and combined.
expect(wrapper.html()).toContain("6")
......
......@@ -58,7 +58,7 @@ describe('Quizzes.vue', () => {
expect(wrapper.is(Quizzes)).toBe(true)
})
it('requests and shows the right data', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/quiz-analytics/1/", {
moxios.stubRequest(/.*quiz-analytics*./, {
status: 200,
response: [{
"id": "3Z22zCJ0EeaAvQ6lv8vWPw@3",
......@@ -80,7 +80,7 @@ describe('Quizzes.vue', () => {
})
it('handles empty data', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/quiz-analytics/1/", {
moxios.stubRequest(/.*quiz-analytics*./, {
status: 200,
response: [],
})
......@@ -92,7 +92,7 @@ describe('Quizzes.vue', () => {
})
it('handles api error', (done) => {
moxios.stubRequest(util.apiUrl() + "/api/quiz-analytics/1/", {
moxios.stubRequest(/.*quiz-analytics*./, {
status: 403,
response: [],
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment