forked from G-Research/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo.cy.js
More file actions
157 lines (129 loc) · 4.39 KB
/
repo.cy.js
File metadata and controls
157 lines (129 loc) · 4.39 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
describe('Repo', () => {
let cookies;
let repoName;
describe('Anonymous users', () => {
beforeEach(() => {
cy.visit('/dashboard/repo');
});
it('Prevents anonymous users from adding repos', () => {
cy.get('[data-testid="repo-list-view"]')
.find('[data-testid="add-repo-button"]')
.should('not.exist');
});
});
describe('Regular users', () => {
beforeEach(() => {
cy.login('user', 'user');
cy.visit('/dashboard/repo');
});
after(() => {
cy.logout();
});
it('Prevents regular users from adding repos', () => {
cy.get('[data-testid="repo-list-view"]')
.find('[data-testid="add-repo-button"]')
.should('not.exist');
});
});
describe('Admin users', () => {
beforeEach(() => {
cy.login('admin', 'admin');
cy.visit('/dashboard/repo');
});
it('Admin users can add repos', () => {
repoName = `${Date.now()}`;
cy.get('[data-testid="repo-list-view"]').find('[data-testid="add-repo-button"]').click();
cy.get('[data-testid="add-repo-dialog"]').within(() => {
cy.get('[data-testid="repo-project-input"]').type('cypress-test');
cy.get('[data-testid="repo-name-input"]').type(repoName);
cy.get('[data-testid="repo-url-input"]').type(
`https://github.com/cypress-test/${repoName}.git`,
);
cy.get('[data-testid="add-repo-button"]').click();
});
cy.contains('a', `cypress-test/${repoName}`, { timeout: 10000 }).click();
// cy.get('[data-testid="delete-repo-button"]').click();
});
it('Displays an error when adding an existing repo', () => {
cy.get('[data-testid="repo-list-view"]').find('[data-testid="add-repo-button"]').click();
cy.get('[data-testid="add-repo-dialog"]').within(() => {
cy.get('[data-testid="repo-project-input"]').type('finos');
cy.get('[data-testid="repo-name-input"]').type('git-proxy');
cy.get('[data-testid="repo-url-input"]').type('https://github.com/finos/git-proxy.git');
cy.get('[data-testid="add-repo-button"]').click();
});
cy.get('[data-testid="repo-error"]')
.should('be.visible')
.and('contain.text', 'Repository https://github.com/finos/git-proxy.git already exists!');
});
});
describe('Existing repo', () => {
let cloneURL;
let repoId;
before(() => {
cy.login('admin', 'admin');
// Create a new repo
cy.getCSRFToken().then((csrfToken) => {
repoName = `${Date.now()}`;
cloneURL = `http://localhost:8000/github.com/cypress-test/${repoName}.git`;
cy.request({
method: 'POST',
url: 'http://localhost:8080/api/v1/repo',
body: {
project: 'cypress-test',
name: repoName,
url: `https://github.com/cypress-test/${repoName}.git`,
},
headers: {
cookie: cookies?.join('; ') || '',
'X-CSRF-TOKEN': csrfToken,
},
}).then((res) => {
expect(res.status).to.eq(200);
repoId = res.body._id;
});
});
});
it('Opens tooltip with correct content and can copy', () => {
cy.visit('/dashboard/repo');
cy.on('uncaught:exception', () => false);
const tooltipQuery = 'div[role="tooltip"]';
// Check the tooltip isn't open to start with
cy.get(tooltipQuery).should('not.exist');
// Find the repo's Code button and click it
cy.get(`a[href="/dashboard/repo/${repoId}"]`)
.closest('tr')
.find('span')
.contains('Code')
.should('exist')
.click();
// Check tooltip is open and contains the correct clone URL
cy.get(tooltipQuery)
.should('exist')
.find('span')
.contains(cloneURL)
.should('exist')
.parent()
.find('span')
.next()
.get('svg.octicon-copy')
.should('exist')
.click();
cy.get('svg.octicon-copy').should('not.exist');
cy.get('svg.octicon-check').should('exist');
});
after(() => {
// Delete the repo
cy.getCSRFToken().then((csrfToken) => {
cy.request({
method: 'DELETE',
url: `http://localhost:8080/api/v1/repo/${repoName}/delete`,
headers: {
cookie: cookies?.join('; ') || '',
'X-CSRF-TOKEN': csrfToken,
},
});
});
});
});
});