Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
twitch
live-coding-fr
Commits
5ea7dcf8
Unverified
Commit
5ea7dcf8
authored
Aug 23, 2020
by
Hippolyte DURIX
Browse files
Init e2e tests
parent
7194bb00
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
5ea7dcf8
...
...
@@ -74,6 +74,9 @@ local.properties
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
.idea/
*.iml
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
...
...
borestop/README.md
View file @
5ea7dcf8
...
...
@@ -54,7 +54,7 @@ The service worker initialization code is commented out by default. To enable it
```
html
<script>
if
(
'
serviceWorker
'
in
navigator
)
{
navigator
.
serviceWorker
.
register
(
'
./service-worker.js
'
).
then
(
function
()
{
navigator
.
serviceWorker
.
register
(
'
./service-worker.js
'
).
then
(
function
()
{
console
.
log
(
'
Service Worker Registered
'
);
});
}
...
...
borestop/e2e/features/Users.test.ts
0 → 100644
View file @
5ea7dcf8
import
{
AxiosInstance
}
from
'
axios
'
;
import
{
createAdminAxiosInstance
,
createUserAxiosInstance
}
from
'
./util/TokenUtils
'
;
let
userAxios
:
AxiosInstance
;
let
adminAxios
:
AxiosInstance
;
describe
(
'
Users
'
,
()
=>
{
beforeAll
(
async
()
=>
{
userAxios
=
await
createUserAxiosInstance
();
adminAxios
=
await
createAdminAxiosInstance
();
});
it
(
'
Should a standard user not be allowed to get all authorities
'
,
async
(
done
)
=>
await
userAxios
.
get
(
'
/api/users/authorities
'
)
.
then
(()
=>
done
(
'
Should status be 401
'
))
.
catch
((
error
)
=>
{
expect
(
error
.
message
).
toContain
(
"
Vous n'avez pas les droits
"
);
done
();
})
);
it
(
'
Should an admin get all authorities
'
,
async
()
=>
{
const
{
data
:
authorities
}
=
await
adminAxios
.
get
(
'
/api/users/authorities
'
);
expect
(
authorities
.
length
).
toBe
(
2
);
});
});
borestop/e2e/features/util/RetryUtils.ts
0 → 100644
View file @
5ea7dcf8
import
ProvidesCallback
=
jest
.
ProvidesCallback
;
import
DoneCallback
=
jest
.
DoneCallback
;
import
{
waitFor
}
from
'
./TimerUtils
'
;
const
runTest
=
(
handler
:
ProvidesCallback
)
=>
new
Promise
((
resolve
,
reject
)
=>
{
const
doneCallback
=
():
DoneCallback
=>
{
const
callback
:
any
=
(
err
:
any
)
=>
(
err
?
reject
(
err
)
:
resolve
());
callback
.
fail
=
()
=>
{};
return
callback
;
};
const
result
=
handler
(
doneCallback
());
if
(
result
&&
result
.
then
)
{
result
.
catch
(
reject
).
then
(
resolve
);
}
else
{
resolve
();
}
});
const
waitBeforeRetry
=
(
time
:
number
)
=>
waitFor
(
time
);
const
withRetriesIt
=
(
name
:
string
,
fn
:
ProvidesCallback
,
maxTries
:
number
,
delay
:
number
,
timeout
?:
number
)
=>
{
it
(
name
,
async
()
=>
{
let
latestError
;
for
(
let
retry
=
1
;
retry
<=
maxTries
;
retry
++
)
{
try
{
await
runTest
(
fn
);
return
;
}
catch
(
error
)
{
latestError
=
error
;
await
waitBeforeRetry
(
delay
);
}
}
throw
latestError
;
},
timeout
);
};
export
interface
RetryConfiguration
{
maxTries
:
number
;
delay
:
number
;
}
export
const
TREEZOR_RETRIES
:
RetryConfiguration
=
{
maxTries
:
20
,
delay
:
500
};
export
interface
WithRetries
{
it
:
(
name
:
string
,
fn
:
ProvidesCallback
,
timeout
?:
number
)
=>
void
;
}
export
const
withRetries
=
(
conf
:
RetryConfiguration
):
WithRetries
=>
({
it
:
(
name
:
string
,
fn
:
ProvidesCallback
,
timeout
?:
number
)
=>
withRetriesIt
(
name
,
fn
,
conf
.
maxTries
,
conf
.
delay
,
timeout
),
});
borestop/e2e/features/util/TimerUtils.ts
0 → 100644
View file @
5ea7dcf8
export
const
waitFor
=
(
delay
:
number
)
=>
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
delay
));
borestop/e2e/features/util/TokenUtils.ts
0 → 100644
View file @
5ea7dcf8
import
axios
,
{
AxiosInstance
}
from
'
axios
'
;
const
SERVER_URL
=
'
http://localhost:8080
'
;
const
enhanceErrorMessage
=
(
error
:
any
)
=>
{
error
.
message
+=
` →
${
error
.
response
.
data
.
errorType
}
("
${
error
.
response
.
data
.
message
}
")`
;
return
Promise
.
reject
(
error
);
};
export
const
createAnonymousAxios
=
()
=>
axios
.
create
({
baseURL
:
SERVER_URL
,
});
const
createUserAxios
=
(
token
:
string
):
AxiosInstance
=>
{
const
instance
=
axios
.
create
({
...{
baseURL
:
SERVER_URL
,
},
headers
:
{
Authorization
:
`Bearer
${
token
}
`
,
},
});
instance
.
interceptors
.
response
.
use
((
response
)
=>
response
,
enhanceErrorMessage
);
return
instance
;
};
export
const
createGivenUserAxios
=
async
(
username
:
string
,
password
:
string
):
Promise
<
AxiosInstance
>
=>
{
const
axiosInstance
=
createAnonymousAxios
();
const
{
data
:
{
'
id_token
'
:
token
}
}
=
await
axiosInstance
.
post
(
'
/api/authenticate
'
,
{
username
,
password
});
return
createUserAxios
(
token
);
};
export
const
createAdminAxiosInstance
=
()
=>
createGivenUserAxios
(
'
admin
'
,
'
admin
'
);
export
const
createUserAxiosInstance
=
()
=>
createGivenUserAxios
(
'
user
'
,
'
user
'
);
borestop/e2e/jest.config.js
0 → 100644
View file @
5ea7dcf8
module
.
exports
=
{
moduleFileExtensions
:
[
'
js
'
,
'
json
'
,
'
jsx
'
,
'
ts
'
,
'
tsx
'
,
'
node
'
],
transform
:
{
'
^.+
\\
.tsx?$
'
:
'
ts-jest
'
,
},
moduleNameMapper
:
{
'
^@/(.*)$
'
:
'
<rootDir>/src/$1
'
,
},
testRegex
:
'
(/__tests__/.*|(
\\
.|/)(test|spec))
\\
.ts?$
'
,
testEnvironment
:
'
node
'
,
setupFilesAfterEnv
:
[
'
./jest.setup.js
'
],
verbose
:
true
,
};
borestop/e2e/jest.setup.js
0 → 100644
View file @
5ea7dcf8
// eslint-disable-next-line no-undef
jest
.
setTimeout
(
55000
);
borestop/e2e/package-lock.json
0 → 100644
View file @
5ea7dcf8
This diff is collapsed.
Click to expand it.
borestop/e2e/package.json
0 → 100644
View file @
5ea7dcf8
{
"name"
:
"e2e"
,
"version"
:
"1.0.0"
,
"description"
:
"End to end tests"
,
"main"
:
"index.js"
,
"scripts"
:
{
"e2e"
:
"jest"
},
"author"
:
"Hippolyte Durix"
,
"license"
:
""
,
"dependencies"
:
{
"@types/axios"
:
"^0.14.0"
,
"axios"
:
"^0.20.0"
,
"typescript"
:
"^4.0.2"
},
"devDependencies"
:
{
"@types/jest"
:
"^26.0.10"
,
"@types/node"
:
"^14.6.0"
,
"jest"
:
"^26.4.1"
,
"ts-jest"
:
"^26.2.0"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment