-
-
Notifications
You must be signed in to change notification settings - Fork 603
Expand file tree
/
Copy pathParseServerTest.js
More file actions
57 lines (49 loc) · 1.8 KB
/
ParseServerTest.js
File metadata and controls
57 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const http = require('http');
const Parse = require('../../node');
describe('ParseServer', () => {
it('can reconfigure server', async () => {
let parseServer = await reconfigureServer({ serverURL: 'www.google.com' });
expect(parseServer.config.serverURL).toBe('www.google.com');
await shutdownServer(parseServer);
parseServer = await reconfigureServer();
expect(parseServer.config.serverURL).toBe('http://localhost:1337/parse');
});
it('can shutdown', async () => {
let close = 0;
const parseServer = await reconfigureServer();
parseServer.server.on('close', () => {
close += 1;
});
const object = new TestObject({ foo: 'bar' });
// Open a connection to the server
const query = new Parse.Query(TestObject);
await query.subscribe();
expect(openConnections.size > 0).toBeTruthy();
await shutdownServer(parseServer);
expect(close).toBe(1);
expect(openConnections.size).toBe(0);
await expectAsync(object.save()).toBeRejectedWithError(
'XMLHttpRequest failed: "Unable to connect to the Parse API"'
);
await reconfigureServer({});
await object.save();
expect(object.id).toBeDefined();
});
it('can forward redirect', async () => {
const serverURL = Parse.serverURL;
const redirectServer = http.createServer(function(_, res) {
res.writeHead(301, { Location: serverURL });
res.end();
}).listen(8080);
Parse.CoreManager.set('SERVER_URL', 'http://localhost:8080/api');
const object = new TestObject({ foo: 'bar' });
await object.save();
const query = new Parse.Query(TestObject);
const result = await query.get(object.id);
expect(result.id).toBe(object.id);
expect(result.get('foo')).toBe('bar');
Parse.serverURL = serverURL;
redirectServer.close();
});
});