-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathrepo.cy.js
More file actions
169 lines (141 loc) · 5.12 KB
/
repo.cy.js
File metadata and controls
169 lines (141 loc) · 5.12 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
158
159
160
161
162
163
164
165
166
167
168
169
/**
* Copyright 2026 GitProxy Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
describe('Repo', () => {
let cookies;
let repoName;
before(() => {
cy.login('admin', 'admin');
cy.cleanupTestRepos();
cy.logout();
});
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('[role="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-submit"]').click();
});
cy.contains('a', `cypress-test/${repoName}`, { timeout: 10000 }).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('[role="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-submit"]').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()}`;
const gitProxyUrl = Cypress.env('GIT_PROXY_URL') || 'http://localhost:8000';
cloneURL = `${gitProxyUrl}/github.com/cypress-test/${repoName}.git`;
const apiBaseUrl = Cypress.env('API_BASE_URL') || Cypress.config('baseUrl');
cy.request({
method: 'POST',
url: `${apiBaseUrl}/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 Code overlay with correct content and can copy', () => {
cy.visit('/dashboard/repo');
cy.on('uncaught:exception', () => false);
// Overlay should not be visible initially
cy.contains('span', cloneURL).should('not.exist');
// Find the repo's Code button and click it
cy.get(`a[href="/dashboard/repo/${repoId}"]`)
.closest('tr')
.contains('button', 'Code')
.should('exist')
.click();
// Verify overlay shows correct clone URL
cy.contains('span', cloneURL).should('be.visible');
// Click the copy to clipboard button (sibling of the clone URL span)
cy.contains('span', cloneURL).parent().find('button').click();
// Verify icon changes from copy to check (confirming clipboard copy)
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: `${Cypress.env('API_BASE_URL') || Cypress.config('baseUrl')}/api/v1/repo/${repoId}/delete`,
headers: {
cookie: cookies?.join('; ') || '',
'X-CSRF-TOKEN': csrfToken,
},
});
});
});
});
});