<commit_before>const { expect } = require('chai');

const app = require('../../../src/app');
const testObjects = require('../helpers/testObjects')(app);
const { generateRequestParamsFromUser } = require('../helpers/services/login')(app);
const { datasourceModel } = require('../../../src/services/datasources/model');

const datasourcesService = app.service('datasources');

describe('datasources service', () => {
	let server;
	before((done) => {
		server = app.listen(0, done);
	});

	after((done) => {
		server.close(done);
		testObjects.cleanup();
	});

	it('registered the datasources service', () => {
		expect(datasourcesService).to.not.be.undefined;
	});

	it('CREATE a new datasource', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv' },
			name: `test${Date.now()}`,
		};
		const result = await datasourcesService.create(data, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config).to.haveOwnProperty('target');
		expect(result.name).to.exist;
		expect(result.createdBy.toString()).to.equal(admin._id.toString());
		expect(result.schoolId.toString()).to.equal(admin.schoolId.toString());
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('protects fields', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv', csvpassword: '<PASSWORD>' },
			name: `test${Date.now()}`,
			protected: ['csvpassword'],
		};
		const result = await datasourcesService.create(data, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config).to.haveOwnProperty('target');
		expect(result.name).to.exist;
		expect(result.createdBy.toString()).to.equal(admin._id.toString());
		expect(result.schoolId.toString()).to.equal(admin.schoolId.toString());
		expect(result.protected).to.not.be.undefined;
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('GET a datasource', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv' },
			name: `test${Date.now()}`,
		};
		const datasource = await datasourcesService.create(data, params);
		params.query = {};
		const result = await datasourcesService.get(datasource._id, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config).to.haveOwnProperty('target');
		expect(result.name).to.exist;
		expect(result.createdBy.toString()).to.equal(admin._id.toString());
		expect(result.schoolId.toString()).to.equal(admin.schoolId.toString());
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('protected fields are protected', async () => {<commit_msg>update a test that didnt actually do anything useful<commit_after>const { expect } = require('chai');

const app = require('../../../src/app');
const testObjects = require('../helpers/testObjects')(app);
const { generateRequestParamsFromUser } = require('../helpers/services/login')(app);
const { datasourceModel } = require('../../../src/services/datasources/model');

const datasourcesService = app.service('datasources');

describe('datasources service', () => {
	let server;
	before((done) => {
		server = app.listen(0, done);
	});

	after((done) => {
		server.close(done);
		testObjects.cleanup();
	});

	it('registered the datasources service', () => {
		expect(datasourcesService).to.not.be.undefined;
	});

	it('CREATE a new datasource', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv' },
			name: `test${Date.now()}`,
		};
		const result = await datasourcesService.create(data, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config).to.haveOwnProperty('target');
		expect(result.name).to.exist;
		expect(result.createdBy.toString()).to.equal(admin._id.toString());
		expect(result.schoolId.toString()).to.equal(admin.schoolId.toString());
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('protects fields', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv', csvpassword: '<PASSWORD>' },
			name: `test${Date.now()}`,
			protected: ['csvpassword'],
		};
		const datasource = await datasourcesService.create(data, params);
		params.query = {};
		const result = await datasourcesService.get(datasource._id, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config.csvpassword).to.not.eq('<PASSWORD>');
		expect(result.protected).to.not.be.undefined;
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('GET a datasource', async () => {
		const admin = await testObjects.createTestUser({ roles: ['administrator'] });
		const params = await generateRequestParamsFromUser(admin);
		const data = {
			config: { target: 'csv' },
			name: `test${Date.now()}`,
		};
		const datasource = await datasourcesService.create(data, params);
		params.query = {};
		const result = await datasourcesService.get(datasource._id, params);
		expect(result).to.not.be.undefined;
		expect(result.config).to.exist;
		expect(result.config).to.haveOwnProperty('target');
		expect(result.name).to.exist;
		expect(result.createdBy.toString()).to.equal(admin._id.toString());
		expect(result.schoolId.toString()).to.equal(admin.schoolId.toString());
		datasourceModel.deleteOne({ _id: result._id }).lean().exec();
	});

	it('protected fields are protected', async () => {
{'fraction_non_alphanumeric': 0.18511133266866067, 'fraction_numerical': 0.00033233632436025255, 'mean_word_length': 4.989054726368159, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6806817', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1835, 'n_words': 327}