-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcp.test.js
More file actions
60 lines (45 loc) · 1.79 KB
/
gcp.test.js
File metadata and controls
60 lines (45 loc) · 1.79 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
58
59
60
const { FieldValue, Firestore } = require('@google-cloud/firestore');
const { setupFirebaseData, deleteFirebaseData } = require('./test_helpers');
const table_name = 'gcp-tests';
const db = new Firestore();
describe('gcp', () => {
jest.setTimeout(10000)
beforeEach(async () => {
return await setupFirebaseData(db, table_name);
});
afterEach(async () => {
return await deleteFirebaseData(db, table_name);
});
const gcp = require('./gcp');
it('should find the correct environment and release it', async () => {
const pr = 'moonswitch/release-qa-env/pr-42';
await gcp(table_name, pr);
const table = db.collection(table_name);
const docs = await table.where('env_name', '==', 'qa6').limit(1).get();
expect(docs.empty).toBe(false);
const doc = docs.docs[0].data();
expect(doc.in_use).toBe(false);
expect(doc.branch).toBeEmpty();
expect(doc.pull_requests).toBeEmpty();
});
it('should remove this pr from environment without releasing it when more than one pr assigned', async () => {
const pr1 = 'moonswitch/release-qa-env/pr-42';
const pr2 = 'moonswitch/other-repo/pr-24';
// Get our test record
const table = db.collection(table_name);
const docs = await table.where('env_name', '==', 'qa6').limit(1).get();
const docRef = docs.docs[0];
// Add another PR to it.
await docRef.ref.update({
pull_requests: FieldValue.arrayUnion(pr2),
});
// Run the action
await gcp(table_name, pr1);
// Refetch our test record
const updatedDocs = await table.where('env_name', '==', 'qa6').limit(1).get();
const doc = updatedDocs.docs[0].data();
expect(doc.in_use).toBe(true);
expect(doc.branch).toBe('test-branch-3');
expect(doc.pull_requests).toEqual(expect.arrayContaining([pr2]));
});
});