<commit_before>require.config
	baseUrl: '../../',
	paths:
		'public/library/models/remote.server': 'tests/mock/remote.server.mock'
		'public/library/models/remote.peer': 'tests/mock/remote.peer.mock'
		'public/library/models/remote.client': 'tests/mock/remote.client.mock'
		'express': 'tests/mock/express.mock'
		'http': 'tests/mock/http.mock'

require [
	'server'
	'public/library/models/remote.client'
	'express'
	'http'
	], ( Server, Client, express, http ) ->
		describe 'Server', ->

			server = null
			
			beforeEach ->
				server = new Server('.')

			describe 'when constructing', ->
				it 'should initialize own variables', ->
					now = Date.now()
					expect(server._initTime).not.toBeGreaterThan(now)
					expect(server._nodes.length).toBe(0)
					expect(server._logs.length).toBe(0)

				it 'should listen for the "debug" event on all nodes', ->
					fakeNode = {
							id: '1'
						}
					server.addNode(fakeNode)
					server._nodes.trigger('debug', fakeNode, 1, 2, 3, 'testMessage')
					expect(server._logs).toEqual([
							[fakeNode.id].concat([1, 2, 3])
						])

				it 'should start up an Express-server', ->
					expect(server._app.get).not.toBe(undefined)
					expect(server._app.configure).not.toBe(undefined)

					describe 'when starting up', ->
						it 'should get configured to relay files', ->
							expect(server._app.configure).toHaveBeenCalled()
							expect(server._app.use).toHaveBeenCalled()
							expect(express.static).toHaveBeenCalled()
							expect(express.static.mostRecentCall.args).toEqual([
									'./public'
								])

						fakeRes = {
									writeHead: jasmine.createSpy('writeHead')
									write: jasmine.createSpy('write')
									end: jasmine.createSpy('end')
								}

						describe 'when /nodes is requested', ->
							callback = null

							beforeEach ->
								callback = server._app._getCallbacks['/nodes']
								fakeRes.writeHead.reset()
								fakeRes.write.reset()
								fakeRes.end.reset()

							it 'should return an empty list when there are no nodes', ->
								expect(callback).not.toBe(undefined)

								spyOn(server, 'getNodes').andReturn([])

								callback(null, fakeRes)

								expect(server.getNodes).toHaveBeenCalled()
								expect(fakeRes.writeHead.mostRecentCall.args).toEqual([
										200
										'Content-Type': 'application/json'
									])
								expect(fakeRes.write.mostRecentCall.args).toEqual([
										'[]'
									])
								expect(fakeRes.end.mostRecentCall.args).toEqual([])

							it 'should return all nodes within 5 seconds', ->
								jasmine.Clock.useMock()

								spyOn(server, 'getNodes').andReturn([{
										query: ->
									}])

								callback(null, fakeRes)

								expect(fakeRes.writeHead.mostRecentCall.args).toEqual([
										200
										'Content-Type': 'application/json'
									])

								expect(fakeRes.write).not.toHaveBeenCalled()
								jasmine.Clock.tick(5001)
								expect(fakeRes.write.mostRecentCall.args).toEqual([
										JSON.stringify({
											error: 'ERR_TIMEOUT'<commit_msg>Fix test that 4241ea93 broke<commit_after>require.config
	baseUrl: '../../',
	paths:
		'public/library/models/remote.server': 'tests/mock/remote.server.mock'
		'public/library/models/remote.peer': 'tests/mock/remote.peer.mock'
		'public/library/models/remote.client': 'tests/mock/remote.client.mock'
		'express': 'tests/mock/express.mock'
		'http': 'tests/mock/http.mock'

require [
	'server'
	'public/library/models/remote.client'
	'express'
	'http'
	], ( Server, Client, express, http ) ->
		describe 'Server', ->

			server = null
			
			beforeEach ->
				server = new Server('.')

			describe 'when constructing', ->
				it 'should initialize own variables', ->
					now = Date.now()
					expect(server._initTime).not.toBeGreaterThan(now)
					expect(server._nodes.length).toBe(0)
					expect(server._logs.length).toBe(0)

				it 'should listen for the "debug" event on all nodes', ->
					fakeNode = {
							id: '1'
						}
					server.addNode(fakeNode)
					server._nodes.trigger('debug', fakeNode, 1, 2, 3, 'testMessage')
					expect(server._logs).toEqual([
							[fakeNode.id].concat([1, 2, 3])
						])

				it 'should start up an Express-server', ->
					expect(server._app.get).not.toBe(undefined)
					expect(server._app.configure).not.toBe(undefined)

					describe 'when starting up', ->
						it 'should get configured to relay files', ->
							expect(server._app.configure).toHaveBeenCalled()
							expect(server._app.use).toHaveBeenCalled()
							expect(express.static).toHaveBeenCalled()
							expect(express.static.mostRecentCall.args).toEqual([
									'./public'
								])

						fakeRes = {
									writeHead: jasmine.createSpy('writeHead')
									write: jasmine.createSpy('write')
									end: jasmine.createSpy('end')
								}

						describe 'when /nodes is requested', ->
							callback = null

							beforeEach ->
								callback = server._app._getCallbacks['/nodes']
								fakeRes.writeHead.reset()
								fakeRes.write.reset()
								fakeRes.end.reset()

							it 'should return an empty list when there are no nodes', ->
								expect(callback).not.toBe(undefined)

								spyOn(server, 'getNodes').andReturn([])

								callback(null, fakeRes)

								expect(server.getNodes).toHaveBeenCalled()
								expect(fakeRes.writeHead.mostRecentCall.args).toEqual([
										200
										'Content-Type': 'application/json'
									])
								expect(fakeRes.write.mostRecentCall.args).toEqual([
										'[]'
									])
								expect(fakeRes.end.mostRecentCall.args).toEqual([])

							it 'should return all nodes within 5 seconds', ->
								jasmine.Clock.useMock()

								spyOn(server, 'getNodes').andReturn([{
										query: ->
										isStructured: true
									}])

								callback(null, fakeRes)

								expect(fakeRes.writeHead.mostRecentCall.args).toEqual([
										200
										'Content-Type': 'application/json'
									])

								expect(fakeRes.write).not.toHaveBeenCalled()
								jasmine.Clock.tick(5001)
								expect(fakeRes.write.mostRecentCall.args).toEqual([
										JSON.stringify({
											error: 'ERR_TIMEOUT'
{'fraction_non_alphanumeric': 0.14408427876823338, 'fraction_numerical': 0.0074554294975688815, 'mean_word_length': 2.492359932088285, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '1666383', 'n_tokens_mistral': 2798, 'n_tokens_neox': 1884, 'n_words': 321}