'use strict';

const assert = require('assert');
const app = require('../../../src/app');
const chai = require('chai');

describe('link service', function () {
	const service = app.service('links');
	it('registered the links service', () => {
		assert.ok(service);
	});

	it(`generates a link of length ${service.Model.linkLength} that has the correct target set`, function () {
		const url = "https://schul-cloud.org/register/abcdef?param=1";
		return service.create({target: url})
			.then(data => {
				chai.expect(data.id).to.have.lengthOf(service.Model.linkLength);
				chai.expect(data.target).to.equal(url);
			});
	});
});

@@ -112,16 +112,76 @@
 'chai');
+%0Aconst chaiHttp = require('chai-http');%0A%0Achai.use(chaiHttp);
 %0A%0Adescri
@@ -247,17 +247,16 @@
 ce('link
-s
 ');%0A%09it(
@@ -623,16 +623,16 @@
 ength);%0A
-
 %09%09%09%09chai
@@ -667,16 +667,334 @@
 l(url);%0A
+%09%09%09%09return Promise.resolve(data.id);%0A%09%09%09%7D)%0A%09%09%09.then(id =%3E %7B%0A%09%09%09%09return new Promise((resolve, reject) =%3E %7B%0A%09%09%09%09%09chai.request(app)%0A%09%09%09%09%09%09.get(%60/link/$%7Bid%7D%60)%0A%09%09%09%09%09%09.end((error, result) =%3E %7B%0A%09%09%09%09%09%09%09if(error) return reject(error);%0A%09%09%09%09%09%09%09chai.expect(result.redirects%5B0%5D).to.equal(url);%0A%09%09%09%09%09%09%09resolve();%0A%09%09%09%09%09%09%7D);%0A%09%09%09%09%7D);%0A%0A
 %09%09%09%7D);%0A%09

Add test for redirects