Fakultas Ilmu Komputer UI

Commit 8586a16d authored by Lia Yuliana's avatar Lia Yuliana
Browse files

[CHORES] add getToken function in authSlice.js

parents 5c74cf39 e44e73c2
......@@ -4,7 +4,8 @@
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:testing-library/recommended"
"plugin:testing-library/recommended",
"plugin:cypress/recommended"
],
"env": {
"browser": true,
......
......@@ -68,6 +68,23 @@ build:
paths:
- node_modules/
integration:
image: cypress/browsers:node12.16.2-chrome81-ff75
stage: test-build
script:
- apt-get install xvfb
- npm run cypress:install
- npm run start:gitlab
- npm run cypress:gitlab
except:
changes:
- "README.md"
cache:
key: dependency
policy: pull
paths:
- node_modules/
SonarScanner Dev:
image:
name: sonarsource/sonar-scanner-cli:4.6
......
{
"baseUrl": "http://localhost:3000",
"video": false,
"defaultCommandTimeout": 6000
}
describe('Submit to Backend Validate Email (Success Case)', () => {
beforeEach(() => {
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/validate-email/',
},
{
statusCode: 200,
},
).as('postValidateEmailSuccess')
cy.visit('/login')
cy.contains('Email').type('a@gmail.com')
cy.get('[data-testid=next-button]').click()
})
it('should have correct body response', () => {
cy.wait('@postValidateEmailSuccess').should(({request}) => {
expect(request.body).to.have.property('email')
})
})
it('should directed to next page if email is validated', () => {
cy.wait('@postValidateEmailSuccess')
cy.url().should('include', '/login')
cy.get('[data-testid=password-input]').should('be.visible')
})
})
describe('Submit to Backend Validate Email (Error Case)', () => {
beforeEach(() => {
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/validate-email/',
},
{
statusCode: 400,
body: {non_field_errors: 'Email is not registered yet.'},
},
).as('postValidateEmailError')
cy.visit('/login')
cy.contains('Email').type('a@gmail.com')
cy.get('[data-testid=next-button]').click()
})
it('should show toast error if email is not registered', () => {
cy.wait('@postValidateEmailError')
cy.get('[data-testid=toast-error-login]').should('be.visible')
})
})
describe('Submit to Backend Login (Success Case)', () => {
beforeEach(() => {
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/validate-email/',
},
{
statusCode: 200,
},
).as('postValidateEmailSuccess')
cy.visit('/login')
cy.contains('Email').type('a@gmail.com')
cy.get('[data-testid=next-button]').click()
cy.contains('Password').type('abcdefgh1')
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/login/',
},
{
statusCode: 200,
},
).as('postLoginSuccess')
cy.contains('Masuk').click()
})
it('should have correct body response', () => {
cy.wait('@postLoginSuccess').should(({request}) => {
expect(request.body).to.have.property('email')
expect(request.body).to.have.property('password')
})
})
it('should directed to / and show success toast after success login', () => {
cy.wait('@postLoginSuccess')
cy.url().should('include', '/')
cy.get('[data-testid=toast-homepage]').should('be.visible')
})
})
describe('Submit to Backend Login (Error Case)', () => {
beforeEach(() => {
cy.visit('/login')
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/validate-email/',
},
{
statusCode: 200,
},
).as('postValidateEmailSuccess')
cy.contains('Email').type('a@gmail.com')
cy.get('[data-testid=next-button]').click()
cy.contains('Password').type('abcdefgh1')
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/login/',
},
{
statusCode: 404,
body: {non_field_errors: 'Password is wrong'},
headers: {'access-control-allow-origin': '*'},
delayMs: 500,
},
).as('postLoginError')
cy.contains('Masuk').click()
})
it('shows non field error toast after post error in Login', () => {
cy.wait('@postLoginError')
cy.contains('Password is wrong').scrollIntoView().should('be.visible')
})
})
describe('Submit to Backend Register (Success Case)', () => {
beforeEach(() => {
cy.visit('/register')
cy.contains('Email').type('a@gmail.com')
cy.contains('No Handphone Aktif').type('812345678')
cy.contains('Password').type('abcdefgh1')
cy.contains('Konfirmasi Password').type('abcdefgh1')
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/register/',
},
{
statusCode: 200,
},
).as('postRegisterSuccess')
cy.get('[data-testid=daftar]').click()
})
it('should have correct body response', () => {
cy.wait('@postRegisterSuccess').should(({request}) => {
expect(request.body).to.have.property('email')
expect(request.body).to.have.property('phone_number')
expect(request.body).to.have.property('password')
})
})
it('should directed to / and show success toast after success register', () => {
cy.wait('@postRegisterSuccess')
cy.url().should('include', '/')
cy.get('[data-testid=toast-homepage]').should('be.visible')
})
})
describe('Submit to Backend Register (Error Case)', () => {
beforeEach(() => {
cy.visit('/register')
cy.contains('Email').type('a@gmail.com')
cy.contains('No Handphone Aktif').type('812345678')
cy.contains('Password').type('abcdefgh1')
cy.contains('Konfirmasi Password').type('abcdefgh1')
})
it('shows email error toast after post error in email', () => {
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/register/',
},
{
statusCode: 404,
body: {email: 'Email already exists'},
headers: {'access-control-allow-origin': '*'},
delayMs: 500,
},
).as('postRegisterEmailError')
cy.get('[data-testid=daftar]').click()
cy.wait('@postRegisterEmailError')
cy.contains('Email already exists').scrollIntoView().should('be.visible')
})
it('shows non field error toast after post error in non field', () => {
cy.intercept(
{
method: 'POST',
url: '**/api/v1/auth/register/',
},
{
statusCode: 404,
body: {non_field_errors: 'Password is too common'},
headers: {'access-control-allow-origin': '*'},
delayMs: 500,
},
).as('postRegisterNonFieldError')
cy.get('[data-testid=daftar]').click()
cy.wait('@postRegisterNonFieldError')
cy.contains('Password is too common').scrollIntoView().should('be.visible')
})
})
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// https://github.com/cypress-io/cypress/issues/349
// add --disable-dev-shm-usage chrome flag
on('before:browser:launch', (browser, launchOptions) => {
if (browser.family === 'chromium') {
console.log('Adding Chrome flag: --disable-dev-shm-usage')
launchOptions.args.push('--disable-dev-shm-usage')
}
return launchOptions
})
return config
}
......@@ -1152,6 +1152,162 @@
"resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz",
"integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg=="
},
"@cypress/listr-verbose-renderer": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/@cypress/listr-verbose-renderer/-/listr-verbose-renderer-0.4.1.tgz",
"integrity": "sha1-p3SS9LEdzHxEajSz4ochr9M8ZCo=",
"dev": true,
"requires": {
"chalk": "^1.1.3",
"cli-cursor": "^1.0.2",
"date-fns": "^1.27.2",
"figures": "^1.7.0"
},
"dependencies": {
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"ansi-styles": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=",
"dev": true
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
"ansi-styles": "^2.2.1",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
}
},
"cli-cursor": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
"integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
"dev": true,
"requires": {
"restore-cursor": "^1.0.1"
}
},
"figures": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
"integrity": "sha1-y+Hjr/zxzUS4DK3+0o3Hk6lwHS4=",
"dev": true,
"requires": {
"escape-string-regexp": "^1.0.5",
"object-assign": "^4.1.0"
}
},
"onetime": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k=",
"dev": true
},
"restore-cursor": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
"dev": true,
"requires": {
"exit-hook": "^1.0.0",
"onetime": "^1.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
}
}
},
"@cypress/request": {
"version": "2.88.5",
"resolved": "https://registry.npmjs.org/@cypress/request/-/request-2.88.5.tgz",
"integrity": "sha512-TzEC1XMi1hJkywWpRfD2clreTa/Z+lOrXDCxxBTBPEcY5azdPi56A6Xw+O4tWJnaJH3iIE7G5aDXZC6JgRZLcA==",
"dev": true,
"requires": {
"aws-sign2": "~0.7.0",
"aws4": "^1.8.0",
"caseless": "~0.12.0",
"combined-stream": "~1.0.6",
"extend": "~3.0.2",
"forever-agent": "~0.6.1",
"form-data": "~2.3.2",
"har-validator": "~5.1.3",
"http-signature": "~1.2.0",
"is-typedarray": "~1.0.0",
"isstream": "~0.1.2",
"json-stringify-safe": "~5.0.1",
"mime-types": "~2.1.19",
"oauth-sign": "~0.9.0",
"performance-now": "^2.1.0",
"qs": "~6.5.2",
"safe-buffer": "^5.1.2",
"tough-cookie": "~2.5.0",
"tunnel-agent": "^0.6.0",
"uuid": "^3.3.2"
},
"dependencies": {
"tough-cookie": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
"dev": true,
"requires": {
"psl": "^1.1.28",
"punycode": "^2.1.1"
}
},
"uuid": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
"integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==",
"dev": true
}
}
},
"@cypress/xvfb": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@cypress/xvfb/-/xvfb-1.2.4.tgz",
"integrity": "sha512-skbBzPggOVYCbnGgV+0dmBdW/s77ZkAOXIC1knS8NagwDjBrNC1LuXtQJeiN6l+m7lzmHtaoUw/ctJKdqkG57Q==",
"dev": true,
"requires": {
"debug": "^3.1.0",
"lodash.once": "^4.1.1"
},
"dependencies": {
"debug": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
"integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
"dev": true,
"requires": {
"ms": "^2.1.1"
}
}
}
},
"@eslint/eslintrc": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.0.tgz",
......@@ -1917,6 +2073,40 @@
}
}
},
"@samverschueren/stream-to-observable": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/@samverschueren/stream-to-observable/-/stream-to-observable-0.3.1.tgz",
"integrity": "sha512-c/qwwcHyafOQuVQJj0IlBjf5yYgBI7YPJ77k4fOJYesb41jio65eaJODRUmfYKhTOFBrIZ66kgvGPlNbjuoRdQ==",
"dev": true,
"requires": {
"any-observable": "^0.3.0"
}
},
"@sideway/address": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.1.tgz",
"integrity": "sha512-+I5aaQr3m0OAmMr7RQ3fR9zx55sejEYR2BFJaxL+zT3VM2611X0SHvPWIbAUBZVTn/YzYKbV8gJ2oT/QELknfQ==",
"requires": {
"@hapi/hoek": "^9.0.0"
},
"dependencies": {
"@hapi/hoek": {
"version": "9.1.1",
"resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.1.1.tgz",
"integrity": "sha512-CAEbWH7OIur6jEOzaai83jq3FmKmv4PmX1JYfs9IrYcGEVI/lyL1EXJGCj7eFVJ0bg5QR8LMxBlEtA+xKiLpFw=="
}
}
},
"@sideway/formula": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.0.tgz",
"integrity": "sha512-vHe7wZ4NOXVfkoRb8T5otiENVlT7a3IAiw7H5M2+GO+9CDgcVUUsX1zalAztCmwyOr2RUTGJdgB+ZvSVqmdHmg=="
},
"@sideway/pinpoint": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz",
"integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ=="
},
"@sinonjs/commons": {
"version": "1.8.2",
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz",
......@@ -2205,9 +2395,10 @@
}
},
"@testing-library/user-event": {
"version": "12.8.1",
"resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-12.8.1.tgz",
"integrity": "sha512-u521YhkCKip0DQNDpfj9V97PU7UlCTkW5jURUD4JipuVe/xDJ32dJSIHlT2pqAs/I91OFB8p6LtqaLZpOu8BWQ==",
"version": "12.8.3",
"resolved": "https://registry.npmjs.org/@testing-library/user-event/-/user-event-12.8.3.tgz",
"integrity": "sha512-IR0iWbFkgd56Bu5ZI/ej8yQwrkCv8Qydx6RzwbKz9faXazR/+5tvYKsZQgyXJiwgpcva127YO6JcWy7YlCfofQ==",
"dev": true,
"requires": {
"@babel/runtime": "^7.12.5"
}
......@@ -2440,6 +2631,18 @@
"@types/node": "*"
}
},
"@types/sinonjs__fake-timers": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.2.tgz",
"integrity": "sha512-dIPoZ3g5gcx9zZEszaxLSVTvMReD3xxyyDnQUjA6IYDG9Ba2AV0otMPs+77sG9ojB4Qr2N2Vk5RnKeuA0X/0bg==",
"dev": true
},
"@types/sizzle": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.2.tgz",
"integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==",
"dev": true
},
"@types/source-list-map": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
......@@ -2914,6 +3117,12 @@
"color-convert": "^1.9.0"
}
},
"any-observable": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/any-observable/-/any-observable-0.3.0.tgz",
"integrity": "sha512-/FQM1EDkTsf63Ub2C6O7GuYFDsSXUwsaZDurV0np41ocwq0jthUAYCmhBX9f+KwlaCgIuWyr/4WlUQUBfKfZog==",
"dev": true
},
"anymatch": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.1.tgz",
......@@ -2928,6 +3137,12 @@
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw=="
},
"arch": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/arch/-/arch-2.2.0.tgz",
"integrity": "sha512-Of/R0wqp83cgHozfIYLbBMnej79U/SVGOOyuB3VVFv1NRM/PSFMK12x9KVtiYzJqmnU5WR2qp0Z5rHb7sWGnFQ==",
"dev": true
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
......@@ -3731,6 +3946,12 @@
"file-uri-to-path": "1.0.0"
}
},
"blob-util": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/blob-util/-/blob-util-2.0.2.tgz",
"integrity": "sha512-T7JQa+zsXXEa6/8ZhHcQEW1UFfVM49Ts65uBkFL6fz2QmrElqmbajIDJvuA0tEhRe5eIjpV9ZF+0RfZR9voJFQ==",
"dev": true
},
"bluebird": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
......@@ -3932,6 +4153,12 @@
"isarray": "^1.0.0"
}
},
"buffer-crc32": {
"version": "0.2.13",
"resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
"integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=",
"dev": true
},
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
......@@ -4009,6 +4236,12 @@
"unset-value": "^1.0.0"
}
},
"cachedir": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/cachedir/-/cachedir-2.3.0.tgz",
"integrity": "sha512-A+Fezp4zxnit6FanDmv9EqXNAi3vt9DWp51/71UEhXukb7QUuvtv9344h91dyAxuTLoSYJFU299qzR3tzwPAhw==",
"dev": true
},
"call-bind": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz",
......@@ -4126,6 +4359,12 @@
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA=="
},
"check-more-types": {
"version": "2.24.0",
"resolved": "https://registry.npmjs.org/check-more-types/-/check-more-types-2.24.0.tgz",
"integrity": "sha1-FCD/sQ/URNz8ebQ4kbv//TKoRgA=",
"dev": true
},
"check-types": {
"version": "11.1.2",
"resolved": "https://registry.npmjs.org/check-types/-/check-types-11.1.2.tgz",
......@@ -4227,6 +4466,17 @@
"restore-cursor": "^3.1.0"
}
},
"cli-table3": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.0.tgz",
"integrity": "sha512-gnB85c3MGC7Nm9I/FkiasNBOKjOiO1RNuXXarQms37q4QMpWdlbBgD/VnOStA2faG1dpXMv31RFApjX1/QdgWQ==",
"dev": true,
"requires": {
"colors": "^1.1.2",
"object-assign": "^4.1.0",
"string-width": "^4.2.0"
}
},
"cli-truncate": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-2.1.0.tgz",
......@@ -4304,6 +4554,12 @@
"q": "^1.1.2"
}
},
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"dev": true
},
"collect-v8-coverage": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.1.tgz",
......@@ -4354,6 +4610,13 @@
"resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
"integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w=="
},