mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-13 23:20:05 +00:00
chore: sas9 username parsing bring back
This commit is contained in:
@@ -13,20 +13,31 @@ export const extractUserNameSas9 = (response: string) => {
|
||||
const regex = /"title":\s?".*?"/
|
||||
|
||||
const matched = response?.match(regex)
|
||||
let username = matched?.[0].split(':')[1].trim()
|
||||
let breakIndex = username?.indexOf(' ')
|
||||
let fullName = matched?.[0].split(':')[1].trim()
|
||||
let breakIndex = fullName?.indexOf(' ')
|
||||
|
||||
if (!fullName) return 'unknown'
|
||||
|
||||
dictionary.map((logoutWord) => {
|
||||
const index = username?.indexOf(logoutWord) || -1
|
||||
const index = fullName?.indexOf(logoutWord) || -1
|
||||
|
||||
if (index > -1) {
|
||||
breakIndex = index + logoutWord.length
|
||||
}
|
||||
})
|
||||
|
||||
username = username?.slice(breakIndex, -1)
|
||||
//Cut only name
|
||||
let username = fullName.slice(breakIndex, -1).trim()
|
||||
|
||||
if (!username) return 'unknown'
|
||||
//Create username by SAS method - first 3 chars of every word lowercase
|
||||
const usernameSplit = username.split(' ')
|
||||
username = usernameSplit
|
||||
.map((name: string) =>
|
||||
usernameSplit.length > 1
|
||||
? name.slice(0, 3).toLowerCase()
|
||||
: name.toLowerCase()
|
||||
)
|
||||
.join('')
|
||||
|
||||
return username.trim()
|
||||
return username
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ describe('Extract username SAS9 English - two word logout handled language', ()
|
||||
const response = ` "title": "${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SAS User One')
|
||||
expect(username).toEqual('sasuseone')
|
||||
})
|
||||
|
||||
it('should return username without space after colon', () => {
|
||||
const response = ` "title":"${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SAS User One')
|
||||
expect(username).toEqual('sasuseone')
|
||||
})
|
||||
|
||||
it('should return username with one word user name', () => {
|
||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SasUserOne')
|
||||
expect(username).toEqual('sasuserone')
|
||||
})
|
||||
|
||||
it('should return username unknown', () => {
|
||||
@@ -39,21 +39,21 @@ describe('Extract username SAS9 two word logout unhandled language', () => {
|
||||
const response = ` "title": "${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('out SAS User One')
|
||||
expect(username).toEqual('outsasuseone')
|
||||
})
|
||||
|
||||
it('should return username without space after colon', () => {
|
||||
const response = ` "title":"${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('out SAS User One')
|
||||
expect(username).toEqual('outsasuseone')
|
||||
})
|
||||
|
||||
it('should return username with one word user name', () => {
|
||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('out SasUserOne')
|
||||
expect(username).toEqual('outsas')
|
||||
})
|
||||
|
||||
it('should return username unknown', () => {
|
||||
@@ -64,28 +64,28 @@ describe('Extract username SAS9 two word logout unhandled language', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Extract username SAS9 Spasnish - one word logout languages', () => {
|
||||
describe('Extract username SAS9 Spanish - one word logout languages', () => {
|
||||
const logoutWord = 'Desconexión'
|
||||
|
||||
it('should return username with space after colon', () => {
|
||||
const response = ` "title": "${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SAS User One')
|
||||
expect(username).toEqual('sasuseone')
|
||||
})
|
||||
|
||||
it('should return username without space after colon', () => {
|
||||
const response = ` "title":"${logoutWord} SAS User One",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SAS User One')
|
||||
expect(username).toEqual('sasuseone')
|
||||
})
|
||||
|
||||
it('should return username with one word user name', () => {
|
||||
const response = ` "title": "${logoutWord} SasUserOne",`
|
||||
const username = extractUserNameSas9(response)
|
||||
|
||||
expect(username).toEqual('SasUserOne')
|
||||
expect(username).toEqual('sasuserone')
|
||||
})
|
||||
|
||||
it('should return username unknown', () => {
|
||||
|
||||
Reference in New Issue
Block a user